New answers tagged

2

There is a step in the processing of the command line that is called the quote removal step. This is usually the last thing that happens before the command is executed and it removes the outer sets of quotes that you used to quote strings in the command. For a command such as sed -e "s/a/b/g" this step make sure that the sed command is given the string s/...


1

This looks like a job for bash associative arrays! You can make arrays that take strings as indices. You might know them as "hashes" or "maps" from other languages. Consider the following: $ declare -A packs $ packs=( [low]='1+1+2' [mid]='2+2+3' [high]='3+3+4' ) $ parameters=${packs[low]} $ echo $parameters 1+1+2


0

These both seem to work: bash <(echo 'echo "first: $1 second: $2"') '111' '222' and bash -s '111' '222' < <(echo 'echo "first: $1 second: $2"') looks like the first one, bash is reading from the file descriptor from the first argument, in the second one, it's reading from stdin.


2

You can use a process substitution and redirect the resulting script to Bash's standard input: $ bash -s 'first argument' 'second argument' < <(echo 'printf "%s\n" "$@"') first argument second argument Replace the echo command with curl and you're good. From man bash: If the -s option is present, or if no arguments remain after option processing, ...


0

An easier solution is to write the local declaration and the assignment in two separate statements: This causes the function's exit status to survive as the exit status of the assignment and thus helps to kill the while script in case of an error in the function: some_other_function() { local anothervar anothervar="$(myfunction)" # Do something with "$...


2

This happens because the command in subshell i.e. echo {} | sed 's/\.py/_2\.py/g' executes before echo, so after this command the command will be: xargs -I{} echo {} which will simply echo all the file_names. You can use find command: find directory_name -name '*.py' \ -exec rename 's/.py/_2.py/' {} + It will rename all the files in just one command. ...


Top 50 recent answers are included