Solved

Printing commands during execution of a scrupt

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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

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…
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…
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.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

623 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