Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Verbose output of shell script

Tags:

linux

shell

People also ask

How do I get the verbose output of a shell script?

-v (short for verbose) – tells the shell to show all lines in a script while they are read, it activates verbose mode. -n (short for noexec or no ecxecution) – instructs the shell read all the commands, however doesn't execute them. This options activates syntax checking mode.

How do I run a .sh file in verbose mode?

The -v option tells the shell to run in verbose mode. In practice , this means that shell will echo each command prior to execute the command. This is very useful in that it can often help to find the errors.

What is meant by verbose output?

The verbose option specifies that you want to display detailed processing information on your screen. This is the default. When you run the incremental, selective, or archive commands, information is displayed about each file that is backed up. Use the quiet option if you do not want to display this information.

How do I write a verbose in Bash?

Enabling verbose Mode. We can enable the verbose mode using the -v switch, which allows us to view each command before it's executed. This script checks whether or not the number entered as input is positive.


You don't say what sort of shell you're running. If you're using sh/bash, try

sh -x script_name

to run your script in a verbose/debug mode. This will dump out all the commands you execute, variable values etc. You don't want to do this normally since it'll provide a ton of output, but it's useful to work out what's going on.

As noted in the comments, you can add this flag to your #!/bin/bash invocation in your script.


an easy way:

for i in -20 -19 -18 -17 -16 -15 -14 ... 18 19
do
  echo "Nice value is $i"
  echo "nice -n $i ./app1"
  nice -n $i ./app1
done

These will demonstrate 'eval' and 'set' to do what you want:

::::::::::::::
a.sh
::::::::::::::
#!/bin/sh

clear

i=-20
while [ ${i} -lt 20 ]; do
  echo "Nice value is $i"
  cmd="nice -n $i ./app1"
  echo ${cmd}
  eval ${cmd}
  i=`expr ${i} + 1`
done

::::::::::::::
b.sh
::::::::::::::
#!/bin/sh

clear

i=-20
while [ ${i} -lt 20 ]; do
  echo "Nice value is $i"
  set -x
  nice -n $i ./app1
  set +x
  i=`expr ${i} + 1`
done