LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices

Reply
 
LinkBack Search this Thread
Old 02-28-2013, 06:08 AM   #1
Dman58
Member
 
Registered: Nov 2010
Location: The Danger Zone
Distribution: Slackware, Mint, & random selection for VM
Posts: 213

Rep: Reputation: 26
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
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,524
Blog Entries: 51

Rep: Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601
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
Dman58
Member
 
Registered: Nov 2010
Location: The Danger Zone
Distribution: Slackware, Mint, & random selection for VM
Posts: 213

Original Poster
Rep: Reputation: 26
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.
 
  


Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are 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


All times are GMT -5. The time now is 10:36 PM.

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