Last active
February 27, 2020 13:32
-
-
Save nitesh8860/aca2c8585f59518233c5117842a6c569 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Note that spaces cannot be used around the `=` assignment operator | |
whom_variable="World" | |
# Use printf to safely output the data | |
printf "Hello, %s\n" "$whom_variable" | |
> Hello, World | |
#If you want to bash to expand your argument, you can use Weak Quoting: | |
#!/usr/bin/env bash | |
world="World" | |
echo "Hello $world" | |
> Hello World | |
#If you don't want to bash to expand your argument, you can use Strong Quoting: | |
#!/usr/bin/env bash | |
world="World" | |
echo 'Hello $world' | |
>Hello $world | |
#DEBUG | |
bash -x hello.sh | |
#The -x argument enables you to walk through each line in the script. One good example is here: | |
#change to the Directory of the Script | |
cd "$(dirname "$(readlink -f "$0")")" | |
#list Files Without Using `ls` | |
printf "%s\n" * | |
files=( * ) | |
for file in "${files[@]}"; do | |
echo "$file" | |
done | |
#list files sorted with size | |
ls -l -S ./Fruits | |
#cat options | |
cat -n #show line numbers | |
#To skip empty lines when counting lines, use the --number-nonblank, or simply -b. | |
cat -b file | |
>1 line 1 | |
2 line 2 | |
3 line 4 | |
4 line 5 | |
cat -A #show special characters,tabs,linefeeds | |
#primary purpose of cat. | |
cat file1 file2 file3 > file_all | |
cat file1.gz file2.gz file3.gz > combined.gz | |
#print file reverse | |
tac file.txt | |
#A here document can be used to inline the contents of a file into a command line or a script: | |
cat <<END >file | |
Hello, World. | |
END | |
#The token after the << redirection symbol is an arbitrary string which needs to occur alone on a line (with no leading | |
#or trailing whitespace) to indicate the end of the here document. You can add quoting to prevent the shell from | |
#performing command substitution and variable interpolation: | |
cat <<'fnord' | |
Nothing in `here` will be $changed | |
fnord | |
#(Without the quotes, here would be executed as a command, and $changed would be substituted with the value of | |
#the variable changed -- or nothing, if it was undefined.) | |
#show non printable characters | |
echo '” `' | cat -A | |
>M-bM-^@M-^] `$ | |
#alias | |
alias now='date' | |
unalias {alias_name} | |
echo There are ${#BASH_ALIASES[*]} aliases defined. | |
for ali in "${!BASH_ALIASES[@]}"; do | |
printf "alias: %-10s triggers: %s\n" "$ali" "${BASH_ALIASES[$ali]}" | |
done | |
alias -p | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment