Solved

Printing commands during execution of a scrupt

Posted on 2014-04-06
3
386 Views
Last Modified: 2014-04-06
In RHEL, I want to run a script and have it print out botht he command and the output of the sommand

Right now all I get is the following

[root@mmclnt1 test]# cat a.sh
ls

[root@mmclnt1 test]# ./a.sh
a.sh     

Open in new window


The output I am looking for is something like

[root@mmclnt1 test]# ./a.sh
ls
a.sh     

Open in new window


How can I do this
0
Comment
Question by:Anthony Lucia
3 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 250 total points
ID: 39981701
Try adding "set -x" near the top of the script, or modify the "shebang" line ("#!/bin/bash" or "#!/bin/ksh" or similar), if any, to contain "#!/bin/bash -x" or "#!/bin/ksh -x"
0
 
LVL 34

Assisted Solution

by:Dan Craciun
Dan Craciun earned 250 total points
ID: 39981696
edster9999 already gave you the solution: http://www.experts-exchange.com/OS/Linux/Q_28406238.html#a39981678

bash -x ./a.sh
0
 
LVL 48

Expert Comment

by:Tintin
ID: 39981921
You are better off using

set -v

rather than

set -x


With "set -v", it will output the exact command the script is running.  With "set -x" it will run the command with arguments/variables expanded.

Here's an example:

$ cat a
var=123
echo $var

$ sh -v a
var=123
echo $var
123

$ sh -x a
+ var=123
+ echo 123
123
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Why VNC doesn't work in Redhat? 11 61
php ssh2_scp_send 1 60
Fetching data from Multiple Linux Server using Shell Scripting 55 134
Can't ping New Linux Servers 40 65
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question