How to output return code in shell?
echo $? >> /path/to/return_code $? has the return code of the last statement in bash.
echo $? >> /path/to/return_code $? has the return code of the last statement in bash.
The difference is that (by default) zsh does not do word splitting for unquoted parameter expansions. You can enable “normal” word splitting by setting the SH_WORD_SPLIT option or by using the = flag on an individual expansion: ls ${=args} or setopt SH_WORD_SPLIT ls $args If your target shells support arrays (ksh, bash, zsh), then you … Read more
Printing the Environment from the Shell As other answers have pointed out, one can use /usr/bin/env or /usr/bin/printenv from the command line to see what the environment is in the shell before starting Rails, or in a subshell after starting it. For example: rails s RETURN CTRL-Z env RETURN fg RETURN Displaying ENV from the … Read more
The problem is that jq is still just outputting lines of text; you can’t necessarily preserve each array element as a single unit. That said, as long as a newline is not a valid character in any object, you can still output each object on a separate line. get_json_array | jq -c ‘.[]’ | while … Read more
Use git -C <path> rev-parse. It will return 0 if the directory at <path> is a git repository and an error code otherwise. Further Reading: rev-parse -C <path>
You can use the += operator to append to an array. args=() for i in “$@”; do args+=(“$i”) done echo “${args[@]}” This shows how appending can be done, but the easiest way to get your desired results is: echo “$@” or args=(“$@”) echo “${args[@]}” If you want to keep your existing method, you need to … Read more
The simplest method is to simply use a wildcard: git diff — ‘*AssemblyInfo.cs’ At least this works on my Git v1.8.4, bash 3.2, and zsh 5.7.
The reason for source ~/.bashrc not working is the contents on your ~/.bashrc (default one from Ubuntu 12.04). If you look in it you will see on lines 5 and 6 the following: # If not running interactively, don’t do anything [ -z “$PS1” ] && return PS1 variable is set for an interactive shell, … Read more
You can try this sed: sed -i.bak ‘s/^\(VAR5=\).*/\1VALUE10/’ file It gives: VAR1=VALUE1 VAR2=VALUE2 VAR3=VALUE3 VAR4=VALUE4 VAR5=VALUE10 VAR6=VALUE6
cat /etc/passwd -n | grep `whoami` | cut -f1 Surrounding a command in ` marks makes it execute the command and send the output into the command it’s wrapped in.