Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!

Notices

Welcome to LinuxQuestions.org, a friendly and active Linux Community.

You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!

Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.

If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.

Having a problem logging in? Please visit this page to clear all LQ-related cookies.

Introduction to Linux - A Hands on Guide

This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.

Doesn't everybody do this? You don't need to redirect or use fc, just use two terminal windows. One in the regular shell, one in a text editor. Use the shell to test the commands, once you have them right, copy/paste into the text editor to build up the script. You don't need to write out the entire thing in the shell, just the key parts that need some development (greps, awks, etc.).

ok i see what you mean...but what if im using a command thats affecting files...and i want to see the results without actually altering/changing a file...is there a way to do this...or would you just backup the file?

Depends on what it's doing. If it's a rename/move you could just stick an "echo" in front of the command to print out what it's going to do without actually doing it. If it's actually modifying the file you'd need to back it up first.

You'd have the same dilemma running from a terminal as well, the command does what the command does, whether or not it's in a script.

I think string manipulation (including grep), variables, arrays, if statements, and for/while loops are the most important to get down. With that you can knock out most any script. There will of course be faster ways to do a lot of things, such as sed or awk one-liners, but that can come later.

ok i see what you mean...but what if im using a command thats affecting files...and i want to see the results without actually altering/changing a file...is there a way to do this...or would you just backup the file?

just echo what the results would be to the term without actually applying them

Code:

# here where the name change would take place just echo it
# instead
# mv -v "$path"/"$pref"."$ext" "$path"/"$NewFileName"
echo " mv -v "$path"/"$pref"."$ext" "$path"/"$NewFileName" "

yeah, rm as a variable is a brain fart. Sorry.
My point was to emphasize the use of "echo"'ing stuff.

Code:

TRASH_THAT=$(echo rm -fr path/to/my/doom)
echo "$TRASH_THAT"

What gets me is his statement:

Quote:

Originally Posted by sigint-ninja

what is the best way to test a script without having it actually execute or affect the system...do you just redirect it to a file?

The OP wants to know how to "dry run" a script. Depends on the script.
To correctly test a script, one must write the script is my Final Answer.
It is not clear why the OP thinks redirecting is a testing technique...

yeah, rm as a variable is a brain fart. Sorry.
My point was to emphasize the use of "echo"'ing stuff.

Code:

TRASH_THAT=$(echo rm -fr path/to/my/doom)
echo "$TRASH_THAT"

What gets me is his statement:

The OP wants to know how to "dry run" a script. Depends on the script.
To correctly test a script, one must write the script is my Final Answer.
It is not clear why the OP thinks redirecting is a testing technique...

more like a brain explotion lol --- I almost just ran that on / just to see .. that'd been a big oops - goood thing I changed my mind.

I do see the logic in it though - put it into a var first logic
did you even test that ever?