How to echo single quote in bash shell
Answer:
To echo single quote (using single quote only), you can try
# echo foo
foo
# echo \'''foo
'foo
Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.
How to echo single quote in bash shell
Answer:
To echo single quote (using single quote only), you can try
# echo foo
foo
# echo \'''foo
'foo
How to ignore error in Bash script
Answer:
We have learned in the past on how to show the exit status of a given command.
But is it possible ignore the error and return normal exit code even the command has failed?
Yes, pipe "|| true" to the end of command, e.g.
# foo || true
-bash: foo: command not found
# echo $?
0
As you can see even the command foo was not found, our last exit code is still zero.
Split on specific characters on Bash Script's for loop
Answer:
If you want to Bash script's for loop to split on non white-space characters, you can change the IFS, e.g.
#!/bin/bash
IFS='-'
list="a-b-c-d-e"
for c in $list; do
echo $c
done
The above script will split on the character '-'
E.g.
# ./test.sh
a
b
c
d
e
Check if a file exist in Bash Shell
Answer:
The following script demonstrates how to check if a file exist, using shell (Bash) script
#!/bin/bash
if [ -e test.txt ]
then
echo 'The file exists.'
else
echo 'The file does not exist.'
fi
How to add a directory into the PATH environment variable?
Answer:
To add a new directory into the PATH environment variable, you can use the following command.
# export PATH=$PATH:/opt/myprogram/bin
If you want to have this path being set automatically, then follow this article.