Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 02-28-2013, 06:08 AM   #1
Registered: Nov 2010
Location: The Danger Zone
Distribution: Slackware & everything else in a VM
Posts: 286

Rep: Reputation: 29
Test script before actually running it

As I journey through learning more Linux & writing simple bash scripts to do everyday simple tasks I find myself intimidated sometimes by the unknown. Unknown being "what the heck is this script & or command really going to do?"

I've read in the past or at least that's what I interpreted that the "echo" command could be used in order to sample the output of a command before it's actually executed. Sometimes things need to be done with root privileges but I don't want to risk doing something stupid and irreversible to compromise my system.

How would this be done? A sort of dry run that will go through the command without actually executing it? I was looking at the "test" command but that doesn't seem to fit the bill or maybe I'm wrong.
Old 02-28-2013, 06:48 AM   #2
Registered: May 2001
Posts: 29,358
Blog Entries: 55

Rep: Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545
As for "--dry-run" that kind of depends but 'man bash' shows there's a switch for it except "--dry-run" means your script won't do much. "Debugging" by setting "set -Cvxe" on the CLI or running the script as say '/bin/bash -Cvxe /path/to/script' or changing the hashbang line to read "/bin/bash -Cvxe" sets noclobber, verbose and error mode which may help. Most of the time you'll only use "-vx" to see what variables get assigned etc, etc. Stuff will bite you one or more times but that's what practicing is about. As long as you don't violate the first rule (never test scripts as root account user) and as long as you make backups you should be OK.
Old 02-28-2013, 07:27 AM   #3
Registered: Nov 2010
Location: The Danger Zone
Distribution: Slackware & everything else in a VM
Posts: 286

Original Poster
Rep: Reputation: 29
Ok I feel a bit better now. In essence that's what I've been doing but in simpler form just using the '-v' option or even multiple -v's if the program supports it. I guess it's mainly practice makes perfect (very good) in order to keep the ball rolling. What I'll do now is continue what I've already implemented and add to it in order to further improve my Linux debugging/troubleshooting knowledge.

& no I don't play around in root land because things can get pretty interesting pretty quickly.

Thanks unSpawn for the fast response.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash Script problem running If test on user entered variables Regnets1 Linux - Newbie 3 02-17-2012 02:21 PM
script to test if a program is running turf Programming 3 09-22-2010 05:42 AM
[SOLVED] Silencing the line "echo test > test/test.txt" in a shell script Arenlor Linux - General 2 06-18-2010 01:37 PM
How do I test whether network-script is running or not in Xen Dom0. tkmsr Linux - Virtualization and Cloud 1 04-10-2010 07:03 PM
Problem running ATI driver test script chrisjbzero Linux - Newbie 1 03-28-2004 03:23 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:55 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration