Hot answers tagged

2

The AR array is passed via the first argument to second.sh. first.sh #!/bin/bash AR=('foo' 'bar' 'a space' 'bat') printf "AR array contains %d elements: " ${#AR[@]} printf "%s " "${AR[@]}" printf "\n" ./second.sh "$AR" ./second.sh "$(printf "(" ; printf "'%s' " "${AR[@]}" ; printf ")")" Note that sh is not used anymore to run the second.sh script. These ...


2

If it was the last command, this will do it: !!:0 !!:2 If you want the last vim command you can do !vim:0 !vim:2 Edited - had the second argument wrong in last example. Look here for more details: https://www.gnu.org/software/bash/manual/html_node/Word-Designators.html#Word-Designators


2

If you want to use a pipe, then your python script would have to read from stdin. Your script doesn't do that. Instead it expects a file name on the command line. This can be accomplished using a shell feature called process substitution to connect the two together: script.py <(awk '{if ($4 == 1975) print $1,$2,$3}' input.txt) <(...) denotes ...


2

This is easier and only uses grep: grep -B1 PATTERN debug.log | grep -v 'PATTERN\|--' or, grep -B1 PATTERN debug.log | grep -v -e 'PATTERN' -e '--'


1

If the directories you want to preserve are exactly the mountpoints, you might be able to use --one-file-system in GNU rm. I haven't investigated how this is implemented, but I'm guessing that this won't do what you want if the bind mount is from within the same filesystem, so be careful! rm doesn't have a --no-act option, but you can pipe yes no | rm -ir ...


1

Add one character: #!/bin/bash AR=('foo' 'bar' 'baz' 'bat') for i in ${!AR[*]}; do ← echo "$i" done (Add an exclamation mark (!) to the array expansion: ${!AR[*]}.)  From the man page: Parameter Expansion        ︙ ${!name[@]} ${!name[*]} List of array keys.  If name is an ...


1

I have a line in my ~/.bash_profile (from Ubuntu) that might do the trick: # check the window size after each command and, if necessary, # update the values of LINES and COLUMNS. shopt -s checkwinsize You can run this first in the Terminal window to see if it works, and if it does, add it to your own ~/.bash_profile. Alternatively, you could reset ...



Only top voted, non community-wiki answers of a minimum length are eligible