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
Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.
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
How to check the bash shell version
Answer:
To check the current bash shell version
# bash -version
GNU bash, version 3.2.48(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.
How to execute a command repeatedly using bash
Answer:
The following simple bash script will run the echo command, sleep 10 seconds repeatedly.
#!/bin/bash
while [1];
do
echo "Hello!";
sleep 10;
done