Solved

Printing commands during execution of a scrupt

Posted on 2014-04-06
3
392 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 35

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses

734 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