- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: run shell script and display/print resultant ...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2008 08:08 AM
10-21-2008 08:08 AM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2008 09:23 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2008 09:33 AM
10-21-2008 09:33 AM
Re: run shell script and display/print resultant commands
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2008 11:10 AM
10-21-2008 11:10 AM
Re: run shell script and display/print resultant commands
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2008 11:21 AM
10-21-2008 11:21 AM
Re: run shell script and display/print resultant commands
"-x" output?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2008 11:32 AM
10-21-2008 11:32 AM
Re: run shell script and display/print resultant commands
> the resultant output doesn't show me the statements with the variable substitutions.
True, this is what you get. If you want additional tracing/debugging then I think you are going to have to add your own.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2008 12:40 PM
10-21-2008 12:40 PM
Re: run shell script and display/print resultant commands
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2008 02:33 PM
10-21-2008 02:33 PM
Re: run shell script and display/print resultant commands
Well, with "-n", the commands are not
executed, so variable assignments don't
happen, and "-x", which shows what gets
executed, does nothing. Without "-n", things
happen, and "-x" shows something.
dy # cat xv.sh
#!/bin/sh
var='fred'
echo "$var"
dy # sh xv.sh
fred <-- Normal output.
dy # sh -v xv.sh
#!/bin/sh
var='fred' <-- "-v" output.
echo "$var" <-- "-v" output.
fred
"-v" shows what the shell has got before it
interprets it. So, "-v" shows "$var", not
"fred". Adding "-n" stops the "echo" from
acting, but you still see the (unevaluated)
statements:
dy # sh -vn xv.sh
#!/bin/sh
var='fred'
echo "$var"
"-x" shows what the shell executes:
dy # sh -x xv.sh
+ var=fred
+ echo fred
fred
dy # sh -xn xv.sh
dy #
If you want to see evaluated variables, then
you need to execute the script. To me, using
"-n" and "-x" together makes little sense.
Never trust the advice you get here, I always
say.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2008 02:39 PM
10-21-2008 02:39 PM
Re: run shell script and display/print resultant commands
together:
dy # sh -vx xv.sh
#!/bin/sh
var='fred'
+ var=fred
echo "$var"
+ echo fred
fred
The "+ " prefix helps to identify the "-x"
output, but the mixed output can get
confusing when more complex statements are
used (conditional and looping statements,
"eval", and so on).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2008 02:42 PM
10-21-2008 02:42 PM
Re: run shell script and display/print resultant commands
> Steven: Never trust the advice you get here, I always say.
Well, now, the OP stated: "...allow me to run a shell file and show/print the statements that are generated without executing the statements"
So, what does that suggest to you? Oh, never mind, your cynical remarks far outweigh the insights you *could* share.
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2008 05:41 PM
10-21-2008 05:41 PM
Re: run shell script and display/print resultant commands
So why _would_ it make sense to use "-x" with
"-n"? My insight is insufficient to explain
that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2008 12:04 AM
10-22-2008 12:04 AM
Re: run shell script and display/print resultant commands
That's correct, it didn't make sense to me either. The only way it would make sense is that you remember "-xvn" as one string and take out the "n" if you want to execute. (Or add "x" and remove "n".)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2008 03:46 AM
10-22-2008 03:46 AM
Re: run shell script and display/print resultant commands
> Dennis: The only way it would make sense is that you remember "-xvn" as one string and take out the "n" if you want to execute. (Or add "x" and remove "n".)
Yes, thank you Dennis. That indeed was my point, although by inference rather than consise statement.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2008 11:50 AM
10-22-2008 11:50 AM
Re: run shell script and display/print resultant commands
Well, now, the OP stated: "...allow me to run a shell file and show/print the statements that are generated without executing the statements"
What does this mean.... what OP.... and what would be the options that would be used to get the generated script without execution ???
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2008 12:13 PM
10-22-2008 12:13 PM
Re: run shell script and display/print resultant commands
> ...what OP...
OP = Original Poster (you). I was responding to the remark "...Never trust the advice you get here..." by quoting your original post's sepcifications.
In all, you could do:
# sh -vx file
...to execute and trace
OR:
# sh -vn file
...to NOT execute but list [no so useful unless there is a syntax error]
As I said before, I think to interpret for syntax only AND print the statements generated while prohibiting actual execution, you are going to have to add your own debugging displays.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2008 12:20 PM
10-22-2008 12:20 PM
Re: run shell script and display/print resultant commands
Original Poster (that is, you)?
> and what would be the options that would be
> used to get the generated script without
> execution ???
"-v" shows you what the shell sees. "-x"
shows you what the shell does. In general,
the shell can't know what it will do unless
it does it.
If you wish to test a script which contains
a dangerous command, you can often do it by
inserting an "echo". For example, instead
of:
rm "${fred}"
use:
echo rm "${fred}"
Then if you like the looks of the resulting
commands, remove the "echo".
It's possible to make that a run-time
decision, too, but it can get messy.
Or, you can write a script which writes a
script, and you can inspect that before
running it, and so on. (Many things are
possible, but my reading your mind to learn
what problem you're really trying to solve is
not one of them.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2008 12:48 PM
10-22-2008 12:48 PM
Re: run shell script and display/print resultant commands
#!/bin/sh
ECHO=echo
$echo ls -l
when done debugging, set ECHO=,
or paramaterize it perhaps