How to echo a tab in bash?
Answer:
In Bash script, if you want to print out unprintable characters such as tab, you need to use -e flag together with the echo command.
E.g.
echo -e "\tfoo\tbar"
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 a tab in bash?
Answer:
In Bash script, if you want to print out unprintable characters such as tab, you need to use -e flag together with the echo command.
E.g.
echo -e "\tfoo\tbar"
Simple environment variable usage in Linux
Answer:
In Linux, the most basic way to set an environment variable is use the "=" operator.
For example:
# foo=bar
# echo $foo
bar
Multi-line strings in Bash
Answer:
Bash support multiple line string, e.g.
#!/bin/bash
sort <<EOT
apple
orange
banna
EOT
When you execute the script,
# bash test.sh
It gives:
apple
banna
orange
How to perform syntax check on a bash script?
Answer:
You can perform syntax check on a bash script, without actually running it using the following command:
# bash -n script.sh
But if your script contain execution of other program, bash will not try to run it, even if it does not exist, error of this type will not be returned.
How to unset an environment variable in bash
Answer:
To unset an environment variable in bash, you can use the unset command.
Example:
# export foo=bar
# echo $foo
bar
# unset foo
# echo $foo