The command
ls > dirlist 2>&1
directs both standard output (file descriptor 1) and standard error (file descriptor 2) to the file dirlist, while the command
ls 2>&1 > dirlist
directs only the standard output to file dirlist, because the standard error was made a copy of the standard output before the standard output was redirected to dirlist.
To conclude, the order of redirections is significant.
Ref:- https://www.gnu.org/software/bash/manual/html_node/Redirections.html → 5th paragraph.
shift "$((OPTIND-1))"
Notes:
current_minute=`date +'%M'` clean_up_start_minute=40 clean_up_end_minute=50 if (( $current_minute >= $clean_up_start_minute )) && (( $current_minute < $clean_up_end_minute )) ; then /* do something */ fi
$ (( 5 >= 15 )) && (( 5 < 30 )) && echo 1 || echo 0 0 $ (( 15 >= 15 )) && (( 15 < 30 )) && echo 1 || echo 0 1 $ (( 20 >= 15 )) && (( 20 < 30 )) && echo 1 || echo 0 1 $ (( 30 >= 15 )) && (( 30 < 30 )) && echo 1 || echo 0 0 $ (( 35 >= 15 )) && (( 35 < 30 )) && echo 1 || echo 0 0
tags | equality
current_minute=`date +'%M'` clean_up_minute=15 if [ "$current_minute" -eq "$clean_up_minute" ]; then /* do something */ fi
It works for both positive and negative integers.
$ [ 15 -eq 2 ] && echo 1 || echo 0 0 $ [ 15 -eq 15 ] && echo 1 || echo 0 1 $ [ -15 -eq 15 ] && echo 1 || echo 0 0 $ [ -15 -eq -15 ] && echo 1 || echo 0 1
But not for floating point numbers
$ [ 1.5 -eq 2 ] && echo 1 || echo 0 bash: [: 1.5: integer expression expected 0 $ [ 15 -eq 2.0 ] && echo 1 || echo 0 bash: [: 2.0: integer expression expected 0 $ [ 2.0 -eq 2.0 ] && echo 1 || echo 0 bash: [: 2.0: integer expression expected 0
Put the variable in double quotes to prevent field splitting
echo "$a"
Example:
$ a='^ foo|' $ echo $a ^ foo| $ echo "$a" ^ foo|
search tags | string concatenation multiple spaces
appliances=("AC" "TV" "Mobile" "Fridge" "Oven" "Blender") appliances+=("Dish Washer") for appliance in "${appliances[@]}" do echo $appliance done
languages=("PHP" "MySQL" "Bash" "Oracle") languages[${#languages[@]}]="Python" for language in "${languages[@]}" do echo $language done
fruits=("Banana" "Mango" "Watermelon" "Grape") fruits=(${fruits[@]} "Jack Fruit") for fruit in "${fruits[@]}" do echo $fruit done
men=("John" "Watson" "Micheal") women=("Lisa" "Ella" "Mila") people=(${men[@]} ${women[@]}) for person in "${people[@]}" do echo $person done
Ref:-