Most voted "bash" questions
Bash is a very popular shell (command interpreter). Using the commands provided by Bash itself (built-in Commands) we can perform a series of operations in sequence or create quite complex scripts/programs.
Learn more…291 questions
Sort by count of
-
1
votes0
answers237
viewsLinux script to e-mail the result of the find command
I need a help in a script to send a result by email to a search (find) and run every day at 8:00 am without using contrab on linux
-
1
votes2
answers878
viewsSubtract shellscript input argument value
I have the script below that prints on the screen the even numbers of 1 until the input argument. #!/bin/bash for i in $(seq 1 ($1)); do if [ $(($i % 2)) -eq 0 ] then echo "$i \c" fi done For…
-
1
votes3
answers1757
viewsProblem creating script . sh to enter a directory
I am creating a script. sh that the first step is to enter a directory. 1. #!/bin/bash cd /home/salariosbrasil/consulta-ninja #git pull pwd this directory exists and yet the cd doesn’t work.. but if…
-
1
votes2
answers152
viewsHow to cut a suffix from an expression in bash (egrep/sed/etc)
I’m making a script that works with directories that have suffixes defined and separated by "." for example "folder.teste.git" or "things.var" and would like to take as variable only the prefix…
-
1
votes1
answer259
viewsConvert . log file to . txt in Bash
Hello, I wonder how I can convert a. log file generated in a container in Docker and convert it to a txt file using Bash.
-
1
votes1
answer31
viewsEach round loop var exchange
I am developing a shell system that has a form to add some fields. Quantity Product Valorunitario etc... I need every time the loop changes a variable, so I call it in the form! In the case is the…
-
1
votes1
answer31
viewslibav - save (segmented) stream capture with timestamp in file name
I was looking on the internet to make a home DVR (using a Linux machine) and what I found was this avconv command: avconv -i rtsp://<user>:<password>@xxx.xxx.xxx.xxx:xxx/play1.sdp -c…
-
1
votes1
answer147
viewsSlow bash script
I use a bash script to translate words from other languages into Portuguese. It always worked very well, but from a few days to here became extremely slow, to the point that I could not use it. some…
-
1
votes3
answers102
viewsReplace command output with a custom message
I am creating a script where at the end of it I run a command that displays a very large output of information. Is it possible to override this output? That is, instead of showing the default output…
-
1
votes1
answer167
viewsHow to generate directory list and perform actions for each list item?
I am trying to build a Shell Script that stores directories exists at the root of /Volumes and perform an iteration on these, ignoring only the directory: "Preboot" and "Macintosh H"
bashasked 7 years, 2 months ago Fábio Jânio 3,407 -
1
votes3
answers505
viewsRun Mysql command when starting the system
Other commands I managed to execute when Boot in the OS normally in these two ways: 1 - Creating a file .sh in the briefcase /etc/init.d/ and put the command inside. 2 - Placing at the end of the…
-
1
votes2
answers841
viewsReplace "[" with [ using sed
I am trying to fix some formatting errors of a file and have as input: "[""teste""]" And I wanted to get an output like: ["teste"] I’ve tried this command but it makes me wrong: sed -i s/"["/[/g…
-
1
votes1
answer3365
viewsWrite linux bash exits to a file
I need to do some tests on the linux command line, but doing all the tests is very time consuming, someone can help me, if you have, to write code in shell script to run all the tests, and record…
-
1
votes1
answer147
viewsShow only lines that appear more than x times. (shell script)
I am analyzing a log file and I wanted to filter only lines that appear more than 10 times inside the file. Only I’m not finding a way to make this filter.…
-
1
votes2
answers466
viewsCheck empty directories and pick up command output
I own a folder called work and inside it I have 2 folders: p1 and p2. How can I know if the folders p1 and p2 are empty ? I have the following command find . -type f -printf "%T@ %p\n" | sort -nr |…
-
1
votes0
answers91
viewssyntax error near Unexpected token `fi'
I’m new and I’m having trouble with the script below: echo "Enter an A, B or C" read letter if [[ $letter == "A" || $letter == "a" ]]; then echo "this is A" elif [[ $input == "B" || $input == "b" ];…
-
1
votes1
answer103
viewsHow to dynamically insert a DNS into /etc/hosts via a bash script?
I have a bash script runmydocker.sh whose goal is to retrieve the string sent by the user at the time he is calling this script and create a DNS on etc/hosts. Example: The user (developer) will call…
-
1
votes2
answers8165
viewsShell Bash, How to pass given from Shel as parameter
i need to run a file file1.sh, but in addition I need to take the data that comes after it, for example: file 1.sh 171.55.8.45, this ip that comes after, in the same line of the file, before…
-
1
votes1
answer146
viewsFlag at command line bash shell
I’m trying to put a flag that can sort or shuffle output, but I could only do that in code and intended it to work when you put the flag in the command to run the file, for example. /bash.sh -r.…
-
1
votes3
answers238
viewsRemove all after ? in file name
Hello! I’m trying to rename a large amount of files on linux, but I’m not getting the command right. The case is as follows: I have several files inside a directory and its subdirectories that have…
-
1
votes1
answer356
viewsShell script take out extension and search only by name
Someone can fix my script? The purpose of the script is to compare the input files with the files in the folder JUNK, the problem is that if the input file is teste1.txt he cannot find the file…
-
1
votes2
answers54
viewsUnexpected exit
I am running this command to remove repeated lines from a file: cat arquivo.csv | (read;echo "$REPLY"; sort) | uniq > arquivo.csv But when I look at the file, it’s blank instead of just the lines…
-
1
votes3
answers56
viewsMass collection of information from files
I intend to collect ctime, atime, mtime and crtime from a considerable mass of files. I have assembled the following script as a partial solution: sudo debugfs -R 'stat <1055890>'…
-
1
votes1
answer105
viewsWhy can’t nohup accept for loop?
I have this code inside a file called test.sh When I try to execute nohup ./teste.sh & he makes that mistake. Someone can explain to me ? ./test.sh: 9: . /test.sh: Syntax error: Bad for loop…
-
1
votes1
answer203
viewsHow to redirect the entire bash script within the script itself?
I need to throw his output into a file instead of playing on the default output which is the screen but without me having to spell it out with the command >> in the terminal, I want the script…
-
1
votes2
answers183
viewsHow to get the Exit code from a command block
Suppose I have the following commands in a script susd systemctl status firewalld If I look at the exit code through echo $? it returns 0 because the last command was executed successfully, but how…
-
1
votes1
answer1088
viewsCopy batch files by renaming them with the original directory name
Suppose I have a directory structure organized as follows on my PC: Diretorio 01 Arquivo 01.jpg Arquivo 02.jpg Arquivo 03.jpg Arquivo 04.jpg Diretorio 02 Arquivo 01.jpg Arquivo 02.jpg Diretorio 03…
-
1
votes1
answer628
viewsHow to get the size of a string array in the shell script?
I have a string that I pass as a parameter, for example : "2,3,4,5" To pick up every item of it I make : #!/bin/bash for ((i=1; i<=4; i++)) do echo "$1" | cut -d "," -f $i done But I would like…
-
1
votes3
answers538
viewsReplace a line from a bash script file
The situation is as follows, I have 3 variables available: numlinha -> line number to be replaced texto -> line text that will be replaced(I would prefer to use the line number but this is…
-
1
votes1
answer34
viewsI can’t identify the error in my script
if [ $# -eq 1 ] then$atletas=$(find treinos -maxdepth 1 -mindepth 1 -type d) for a in $atletas do dados=$(find $a -mindepth 1 -maxdepth 1 -type f -name "????-??-??.txt") …
bashasked 6 years ago Miguel Fortes 11 -
1
votes1
answer739
viewsElectron: Electron-packager: command not found
I’m not able to create the application using the electron. I install the package and when I will execute the command: electron-packager d/dev/puxa Puxa I get the following error message: "Bash:…
-
1
votes2
answers205
viewsHow to pass command result to a bash variable?
I have the following command: cat frutas.txt | tail -n 1 | cut -d: -f 1 This command returns an integer to the terminal. How do I send this value to a variable? I tried something like this: resl=cat…
-
1
votes1
answer443
viewsShell Script for copying renamed file structure to target
I would like to copy a folder structure already renaming the files to their destination by placing in front of the name a text previously informed by the user. But I’m having trouble copying renamed…
-
1
votes1
answer167
viewsAdd bash output to text
Well, I’m trying to create a text log, with the days and times my script was executed. Only, for example: when I use echo 10/03 - 13:20 >> log.txt it overwrites there in the text file by…
-
1
votes1
answer55
viewsHow to format response of a bash command?
My intention is to print on the screen the number of pages of each PDF in a given directory. I even managed to do this through the following command: find "$PWD" -iname "*.pdf" | xargs -i pdfinfo {}…
-
1
votes1
answer54
viewsHow to extract strings from 4 different files, and insert into a single line of an HTML document
For hours I’ve been trying to find a way to include the contents of 4 distinct files for a new output file -; "output.html". The 4 files I’m looking to extract information from are: link.txt…
-
1
votes1
answer168
viewsBash write output in terminal and file
I am creating a script and need the outputs to be shown in the terminal, but also saved in a file #!/bin/bash echo "Olá Mundo" and I am redirecting the output to the file as follows ./teste.sh >…
-
1
votes3
answers354
viewsHow to hide sensitive information in Django?
In my Django project I have some sensitive variables, which I need to 'hide'. In general, save them in a file . env and read them with DADO_SENSIVEL = os.environ.get("DADO_SENSIVEL", default="")..…
-
1
votes1
answer47
viewsStart process with custom name via command line
There is a process in my application that today whenever it runs keeps the name of the function as the name of the process in background. However to perform some mapping, I wanted to customize the…
-
1
votes2
answers277
viewsBashscript. How to execute a command at a given time?
I am trying to create code in Bash Scripting, and I need it to run this script in the background and run this command daily at this predetermined time and run only once. I’m having problems, because…
-
1
votes1
answer161
viewsDialog progress bar (Shell Script)
I would like to create a progress bar for my backup script. The problem is that the rsync command (which is inside the loop) generates duplicate (unnecessary) lines that increase the size of the log…
-
1
votes0
answers50
viewsIs it possible that a script knows where it was called?
I have a script.sh and I wonder if there’s any way he could know where he was called. ex: comando=$(existe algum comando pra isso?) variavel=$AlgumaVariavelDeAmbienteTalvez if [[ $comando == "x" ]];…
-
1
votes1
answer44
viewsError in logic to replace all phrases within an x file using Bash Shell Script
How can I replace all the same phrases within a file, using Bash Shell Script, when receiving the value to be replaced from a variable? 1 - How I would like - but it doesn’t work.:…
-
1
votes1
answer94
viewsLoop through the lines of a file and print parts of it in sequence
I have a text file that has several lines separated by two points. See for example: teste1:testee1 teste2:testee2 teste:testeeee Using a loop for, I’m trying to get the script to print on the screen…
-
1
votes0
answers38
viewsProblems with crontab and Git push script
I created a scrip . sh to update my repository in Git Hub. Manually the scrip runs perfectly. #!/bin/bash cd /home/user/tmp/ git init git add . git commit -m "`date +'%Y_%m_%d'`" git push --force…
-
1
votes1
answer46
viewsHow to know if a variable has already been defined in Bash?
I have an application that runs from a script sh. I have in this script defined some variables, where I use export to be accessed internally by the application. However, now I only need to define…
bashasked 3 years, 11 months ago Wallace Maxters 102,340 -
1
votes1
answer41
viewsUse the command xargs as input from a file to popular Xdialog --radiolist
The question here is very simple! Here is a variable: arquivo="\"Item 1\" 'A' off \"Item 2\" 'B' off \"Item 3\" 'C' off \"Item 4\" 'D' off \"Item 5\" 'E' off \"Item 6\" 'F' off" Note that the length…
-
1
votes4
answers120
viewsHow to filter an HTML tag and its contents with regular expressions in Shell Bash?
Based on the text below, how to keep the text output from the first column of tag span, that matches the text of the latter span? <span class="CVA68e qXLe6d">Colcha Casal e ... -…
-
0
votes2
answers199
viewsHow to check if a provider is on . ssh/known_hosts?
I have a script that synchronizes git repositories. If the repository has never been synchronized, directories are created. Eventually, when a repository is added, the server serving the repository…
-
0
votes1
answer838
viewsHow to identify percentage of memory usage for running cache clean command?
We know that the command for memory cache cleanup is this: sync; echo 3 > /proc/sys/vm/drop_caches However, how to make an executable with a condition (if() Else()), so that this command is…