How do I terminate all the subshell processes?
Here’s a simpler solution — just add the following line at the top of your script: trap “kill 0” SIGINT Killing 0 sends the signal to all processes in the current process group.
Here’s a simpler solution — just add the following line at the top of your script: trap “kill 0” SIGINT Killing 0 sends the signal to all processes in the current process group.
In Bash, you can’t store the NULL-character in a variable. You may, however, store a plain hex dump of the data (and later reverse this operation again) by using the xxd command. VAR1=`echo -ne “n\0m\0k” | xxd -p | tr -d ‘\n’` echo -ne “$VAR1” | xxd -r -p | od -c # -> 0000000 …
Yes; wrap the filter in an array 🙂 $ jq ‘[.[] | select(.id == “second”)]’ tmp.json [ { “id”: “second”, “val”: 2 }, { “id”: “second”, “val”: 3 } ] Or, use map/1, which is predefined as [.[] | …]. $ jq ‘map(select(.id == “second”))’ tmp.json [same result] To wrap the results in a bash …
First, yes, 1>&2 is the right thing to do. Second, the reason your 1>&2 2>errors.txt example doesn’t work is because of the details of exactly what redirection does. 1>&2 means “make filehandle 1 point to wherever filehandle 2 does currently” — i.e. stuff that would have been written to stdout now goes to stderr. 2>errors.txt …
Tmuxinator is also really good for this. Basically you create setup files like so: # ~/.tmuxinator/project_name.yml # you can make as many tabs as you wish… project_name: Tmuxinator project_root: ~/code/rails_project socket_name: foo # Not needed. Remove to use default socket rvm: 1.9.2@rails_project pre: sudo /etc/rc.d/mysqld start tabs: – editor: layout: main-vertical panes: – vim – …
Use quotes: cd “new folder” or escape the space: cd new\ folder (That being said, cd does not open a file but changes the working directory.)
The answer I prefer is following [[ -z “$1” ]] && { echo “Parameter 1 is empty” ; exit 1; } Note, don’t forget the ; into the {} after each instruction
Ctrl+C sends the interrupt signal, SIGINT. You need to tell bash to exit when it receives this signal, via the trap built-in: trap “exit” INT for ((i=0; i < $srccount; i++)); do echo -e “\”${src[$i]}\” will be synchronized to \”${dest[$i]}\”” echo -e $’Press any key to continue or Ctrl+C to exit…\n’ read -rs -n1 rsync …
“Batch File” is terminology normally used for a text file containing a sequence of MSDOS shell commands. Bash is a unix shell, and normally the equivalent term for unix to “Batch File” is “Shell Script”, or simply “Script”. I’ve never heard the term “Bash file”, though it makes some logical sense, usually “Shell Script” or …
If you are using Bash, you are better off using the arithmetic expression, ((…)) for readability and flexibility: if ((number >= 2 && number <= 5)); then # your code fi To read in a loop until a valid number is entered: #!/bin/bash while :; do read -p “Enter a number between 2 and 5: …