How to echo shell commands as they are executed
set -x
or set -o xtrace
expands variables and prints a little + sign before the line.
set -v
or set -o verbose
does not expand the variables before printing.
Use set +x
and set +v
to turn off the above settings.
On the first line of the script, one can put #!/bin/sh -x
(or -v
) to have the same effect as set -x
(or -v
) later in the script.
The above also works with /bin/sh
.
See the bash-hackers' wiki on set
attributes, and on debugging.
$ cat shl
#!/bin/bash
DIR=/tmp/so
ls $DIR
$ bash -x shl
+ DIR=/tmp/so
+ ls /tmp/so
$
Bash script echo and no need to press ENTER
I suspect your issue is related to using echo -ne '\n...'
instead of simply echo '...'
. However, your whole code can be simplified greatly:
#!/bin/bash
while :; do
until ping -c 1 192.168.150.1 > /dev/null; do
echo "Waiting for client to come online"
done
echo "Client is up! We will start the web server"
echo "ServerName 127.0.0.1" > /etc/apache2/httpd.conf
/etc/init.d/apache2 start && break
done
How do I turn off echo in a terminal?
stty_orig=`stty -g`
stty -echo
echo 'hidden section'
stty $stty_orig
Want to echo good error message in case of linux command failed
This:
if echo $? > 0
does not do anything you want it to.
if [ $? -ne 0 ]
How can I write and append using echo command to a file
If you want to have quotes, then you must escape them using the backslash character.
echo "I am \"Finding\" difficult to write this to file" > file.txt echo
echo "I can \"write\" without double quotes" >> file.txt
The same holds true if you i.e. also want to write the \
itself, as it may cause side effects. So you have to use \\
Another option would be to use The `'' instead of quotes.
echo 'I am "Finding" difficult to write this to file' > file.txt echo
echo 'I can "write" without double quotes' >> file.txt
However in this case variable substition doesn't work, so if you want to use variables you have to put them outside.
echo "This is a test to write $PATH in my file" >> file.txt
echo 'This is a test to write '"$PATH"' in my file' >> file.txt
Related Topics
Why Does Cmake Not Respect Library_Path and Cpath
Using a Command That Needs Backticks to Be Passed as Part of an Argument in Bash
Run Multiple Commands At Once in the Same Terminal
Run Jenkins Job as Another User
Awk: Words Frequency from One Text File, How to Ouput into Myfile.Txt
Linux Kernel API Changes/Additions
Some Details on Arm Linux Boot
How to Enable Evp Functions in Openssl
Send a Binary File (Line by Line) to a Socket Server with Netcat
Linux/Module.H No Such File or Directory
If Adding a Command That Repeats Every 10 Minutes to Crontab, When Does the First Job Run
Bash Tail the Newest File in Folder Without Variable
Implement Custom U-Boot Command
What Does the "Mov Rax, Qword Ptr Fs:0X28" Assembly Instruction Do
Erge Text Files Ordered by Numerical Filenames in Bash
Where Did Wireshark/Tcpdump/Libpcap Intercept Packet Inside Linux Kernel