Solved

Printing commands during execution of a scrupt

Posted on 2014-04-06
3
375 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now