Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Printing commands during execution of a scrupt

Posted on 2014-04-06
3
Medium Priority
?
401 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 1000 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 1000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses
Course of the Month10 days, 20 hours left to enroll

885 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