one Flashcards
Starting off with a Sha-Bang
#! tells the script to be fed to a specific interpreter
If the sha-bang is incorrect
Probably I will get “Command not found”
what will #!/bin/sh invoke
It will invoke the default shell interpreter, namely, bash
How to interpret a file manually using bash?
bash filename
Find out the current shell name
cat /etc/shells
echo $SHELL
ps $$
ps -p $$
How to get manuals of commands
man command
command –help
How to find out a command is a built-in or an external binary file
type -a
bash startup scripts
script of commands executed at login to set up environment
login shell
when login shell is started: 1 /etc/profile runs first 2 /etc/profile.d 3 $HOME/.bash_profile which will cass $HOME/.bashrc $HOME/.bash_login $HOME/.profile
logout shell
If log out, it will call $HOME/.bash_logout
find out available binary packages shell list
yum search shell
apt-cache search shell
Display the full path of shell commands
which command
multiple line comment
remove permission
chmod ugo= filename
debug bash script
bash -x scriptname
How to use set to turn on debug mode or turn off debug mode
set -x turn on the debug mode
set +x turn off the debug mode
How to check the syntax error in the bash script
set -n Read the script and check the syntax but don’t output it
display the input lines and show if the line is implemented and show the result
set -v or bash -v
set the bash debug in the bash script without set
!/bin/bash -xv
enable the backslash in echo
echo -e
while disable it by echo -E
view system variables
set
env
printenv
check bash version
echo $BASH_VERSION
how to initialize the environmental variables
write them in the ~/.bash_profile
can we use like $(HOME)
no, the right answer is ${HOME}