What Is Echo $? in Linux Terminal

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



Leave a reply



Submit