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
-
2
votes1
answer113
viewsHow to change Cartesian file coordinates in an automated way
I have a certain folder with several files, and these in turn contain inside description of coordinates points cartesian X and Y. However, I want to replace these points automatically and…
-
2
votes1
answer1009
viewsBulk encoding of files on linux
Hello, I’m needing to do the encoding conversion of files to utf-8 since the application will migrate from server. In this application I have files with several encodings actually, some in utf-8,…
-
2
votes1
answer64
viewsRetrieve arguments passed via ARGV in the terminal
I have a make file. Inside this make file, I call this file that has it: set -f; echo $1 | bc I want to recover function value in C for that Makefile file. Example: ./a.out "12 + 12" result: 24…
-
2
votes1
answer157
viewsHow to treat variable in bash?
I’m having a problem, I’m making a bash script to run using crontab, which synchronizes my SSD files, with the hard drive and Dropbox. Script: #!/bin/bash - PC_DIR="~/Programming"…
-
2
votes1
answer233
viewsHow to create, access and manipulate associative arrays?
I am using GNU-Bash on my Mingw terminal (bash --version: GNU bash, version 4.4.12(1)-release (i686-pc-msys)). I need to create a data dictionary to check if a new key has been found and associate…
bashasked 7 years ago Jefferson Quesado 22,370 -
2
votes1
answer2306
viewsScript to check running process and finish or not
i have a process called monitor.exe and the same can not have 2 active processes because it is a print monitor that if you have 2 active processes the same will issue 2 duplicate tax notes, so I…
-
2
votes3
answers861
viewsHow to recursively rename numbered files by naming other files
What I am currently looking to do is rename all files in a folder, where there are also other files of different format. See Example: FOLDER - BEFORE 1.txt 2.txt 3.txt Daniela.jpg Amanda.jpg…
-
2
votes4
answers117
viewsCopy one line at a time from the source file to the target files
A new need arose accompanied by a good and new question that until then did not find anything similar on the internet - Copy a single line at a time to a different single file. Example for each new…
-
2
votes0
answers35
viewsRead command gets lost when using arrows in Mingw
I need to read a command line information. Here at work we use the Mingw that comes shipped on Sourcetree. For such a need, I tried to use the function built-in of bash read, but it does not behave…
bashasked 6 years, 11 months ago Jefferson Quesado 22,370 -
2
votes2
answers1211
viewsExecute bash commands in C
I’m using the function system("comando"); to execute bash commands in a C program. However, I am having difficulty printing the value of a variable. #include <stdio.h> #include…
-
2
votes3
answers3476
viewsGrep with multiple parameters
I need to select the lines of a file that contains the characters | or \ diff -y ontem.csv hoje.csv | grep -e "|" -e "\" How to tell pro grep to return the lines it contains or a pipe | or a bar \…
-
2
votes2
answers445
viewsRun terminal from Python script
I am doing a work of distributed systems, in which I am using PYRO, in it I am using objeto.adapter.rebindURI() to use the same object when the server that was (dropped) is "restarted"... I’m hoping…
-
2
votes2
answers109
viewsFind and Replace in bash
I need to find outdated lines in a csv file and replace them with new lines. These are the commands that find the lines that will be replaced(old) and that will replace(new). linhas_antigas=$(diff…
-
2
votes1
answer482
viewsScroll through an array bash script
Can someone give me an example of an if and case running through an array in bash script? I’m just finding an example of what it’s for to list the items.. I’m trying to make sure ex: v1=("sim" "s"…
-
2
votes1
answer1549
viewsHow to search for an exact word with the grep command
Well, whenever I use the grep command he looks for a word that contains the desired word + anything, how can I make him understand that I just want that word and nothing else? ex: ps aux|grep bc…
-
2
votes1
answer138
viewsEdit configuration file
I have a configuration file with several parameters, example: campo1=valor campo2=valor campo3= I would like to assign a value to campo3 with Shell Script. I tried to do with awk but I couldn’t. The…
-
2
votes1
answer1166
viewsWhich Way to Recursively Remove Accented Characters from File Names
I tried other scripts I found online (*os I found), but to no avail. So I want to know some of you(s) how to do this automated/recursive task. Shell Script Taken from: https://tsgii.blogspot.com/…
-
2
votes1
answer949
viewsHow to save a variable’s value in a Bash Script function
I am creating a factory to easily encrypt a file in this case in txt or decipher. The problem in this program is the value of the variable CIFRA_HEX and CIPHER that cannot pass the value saved to…
bashasked 6 years, 3 months ago Elio Borges 55 -
2
votes2
answers210
viewsHow to change the file extension recursively in GNU/Linux?
I’m trying to get all the files .sql of my project and change the extension to .md. I’ve been able to do this, however, the files are being moved to the system root, which is the path where the…
-
2
votes1
answer142
viewsRegular Expression is correct but does not enter if
I wonder why my code isn’t getting into this if more internal. I tested regex for some websites and it’s working. I tested with this value: nucepe-2018-pc-pi-perito-criminal-informatica-prova.pdf.…
-
2
votes1
answer174
viewsHow to run find -exec on files that have been modified for more than 15 days?
I am trying to remove some files from a directory, but I cannot mount a command. What I want would be more or less like this: find -name '*.log*' -mtime 15 -exec rm -f {} Find the default name and…
-
2
votes0
answers36
viewsUbuntu 18.04.1 LTS with 100% storage and processing
I’m having a problem with my development server and I can’t fix it. I’ve done a lot of research, but I can’t find the solution. Probably those who have more advanced knowledge of the OS believe it…
-
2
votes2
answers201
viewsswitch case in bash
Man switch case is not working properly: while getopts "hvo:umsf" OPTION do case $OPTION in i) instalarSniper ;; h) help ;; s) simular ;; d) adicionais ;; ?) echo "Parametros incorretos, digite -h…
-
2
votes2
answers186
viewsUnexpected output when printing substring
I’m doing a file search in a given directory and printing its respective path. find ./ -exec sh -c "echo $(dirname "{}")" \; Output: ./algo/desse/tipo Since in some cases this path is a little big,…
-
2
votes2
answers454
viewsHow to create a script to rename files on Ubuntu 18?
I have a folder called baixar-nanatsu and inside the folder I have several videos. I wanted to change the name of the videos via bash or shell script automatically, only I have no idea how it does.…
-
2
votes1
answer187
viewsHow to print vector formatted in Shell?
I’m trying to get a string and change only one of its values, and that’s easy using vectors. However, when printing the string, the vector leaves without formatting, I have tried to print it with…
-
2
votes1
answer55
viewsIs it possible to do two different variable expansions in a single expansion?
I have a variable, in array, $CLI_MODE. I fill it with a simple read: read -a CLI_MODE I would like to take the value of the first tiny element and, if possible, swap - for _. To get everything tiny…
bashasked 5 years, 2 months ago Jefferson Quesado 22,370 -
2
votes1
answer97
viewsWhat is the bash equivalent of python’s sys.argv method?
In python, when I want to use a user-given string in the command line, I use the method sys.argv. For example, let’s say I have an executable called 2name.py consisting of the following code: import…
-
2
votes1
answer167
viewsShell Script to calculate average runtime
I need to perform the same command 10 times and view the average run time. I did the script below, but it always returns the same output, zero, see print below. Could you help me find the error?…
-
1
votes3
answers5312
viewsHow to add line break using sed?
How to add a line break in a pipe received output, using sed, only for cases that fit the established pattern? I used sed "s/.*oo.*/&\n/" unsuccessfully. The pattern is OK, but the addition of…
-
1
votes1
answer15977
viewsadd user to sudoers group on Ubuntu
How to create a user and put it in the sudoers list on linux? How to take an existing user and change your group to sweat?
-
1
votes1
answer97
viewsScript to swap place string with another string
I have the file /etc/udev/rules.d/70-persistent-net.rules that have such interfaces: SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="1c:af:f7:e7:a4:3c", ATTR{dev_id}=="0x0",…
-
1
votes1
answer403
viewsHow to 'Loop' in Multi-dimensional Array in Bash?
Situation: I need to create a multi-dimensional array script. Example: Table 1 >> Campos id and name Table 2 >> Campos id and telephone Current script: #!/bin/bash declare -A arr…
-
1
votes2
answers78
viewsscript does not write to file
I’m putting together a bash script as follows: #!/bin/bash destfile=/home/user/teste.txt array=($(ls 20151* |awk '{ print $9 }')) n=${array[@]} echo "$n" > "$destfile" but when running the script…
-
1
votes1
answer5223
viewsWhat is the Xarg command for?
What is the command for xargs? For example, I’ve seen examples ls pasta/ | xargs -l git update-index I saw that this was being used because the command git update-index does not work with folders.…
-
1
votes1
answer87
viewsHow can I find the user on Ubuntu (Shell/Bash)
I want to create a system that should interactively find the user and then say whether it exists or not. I must provide the username and if the user is found then the system has found the username…
-
1
votes2
answers1591
viewsReceive file lines, and treat them (BASH)
I need a bash script that will read a file, recognize the delimiter (in case ";") and store the values that are in the delimiters in variables, to later mount a menu with the dialog... What I’ve…
-
1
votes1
answer101
viewsRedirect value from time function to file
I’m trying to use the time function on the terminal. When I try to use it only to display always I have the expected return. Commando: time ./main Exit: real 0m0.119s user 0m0.113s sys 0m0.006s But…
-
1
votes1
answer191
viewsHow do I build a script to compile librtmp with openssl?
I’m implementing the project ijkplayer(android mediaplayer) but I’m having a hard time adapting an automated librtmp compilation(rtmpdump). I have the following example below, used to compile…
-
1
votes2
answers174
viewsHow to send commands to the ruby interpreter from a Shell Script?
This is more out of curiosity... I’ve seen some examples of what I want to do, but in Perl. I tried to find a way to do the same in Ruby, but to no avail. I want a function to generate an MD5 hash…
-
1
votes1
answer5766
viewsHow to know if the script command has been successfully executed?
I need the script to identify whether the tar.gz file was successfully generated in an if. Here’s a non-functional example: VAR=tar -zcf teste.tar.gz teste/testeDir if [VAR] then echo "Sucesso" else…
-
1
votes1
answer82
viewsRename children directory and directories
I would like to know how a bash code is made to rename all files of a certain extension and folders that start with a special name. The repository I want to make the changes to:…
bashasked 8 years, 3 months ago Gabriel Oliveira 11 -
1
votes2
answers5127
views -
1
votes2
answers1282
viewsShell/Bash - Script continues before finishing the line that is running
I have a shell/bash script that works perfectly to make backups, the problem is that I have large files that are giving problems in the execution of the script. The script has to compress the file…
-
1
votes1
answer107
viewsRoot permission to change date and time
I would like to know how to get my script to be allowed to change the date and time of the system without asking to enter the root password?
-
1
votes2
answers75
viewsIs there an error in these command lines?
I am comparing documents across Bash’s command lines and using a loop command. However, an error occurs with the results: ./anibatch.sh: line 38: ./ANIcalculator: No such file or directory…
-
1
votes1
answer60
viewsRedirect standard HCIDUMP output using GREP to a file
I am using a shell script to do HCIDUMP and using some filters to write to a file. With the following command, the destination file is empty. hcidump -a l2cap | grep -v -e 'CAP' -e 'HCI' >…
-
1
votes1
answer461
viewsHow to make condition receive a parameter followed by an argument
I’ve been trying to create a structure if..else with a parameter passing. See: Example $ opt-get -i pacote.tgz Yes, I’m creating something similar to tool apt-get of the Operating System Debian. I…
-
1
votes1
answer75
viewsbash program shows no data output
Good afternoon, I program in C and it’s the first time I’m programming in Bash (shell-script). I did some functions in bash, learned to call and created an interactive menu with the user, my program…
-
1
votes3
answers1827
viewsShell Script - compress one file at a time inside the Current Folder
It is the following personal ... I will explain in the least details, in a simple way to illustrate the idea. Example for N in `ls $HOME` do tar zcvf `basename`.tgz $N done See that I want to…
bashasked 7 years, 7 months ago Diego Henrique 2,916