d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Bash Scripting
Add Reply New Topic New Poll
Retired Moderator
Posts: 21,073
Joined: Apr 7 2008
Gold: 5,135.90
Trader: Trusted
Sep 14 2013 09:55pm
Hey guys, I am working on an assignment and the assignment spec sheet says that we need a script that runs like this:
./bashScript.bash nameOfProgram #If the program is like this we need to read 3 integers
or
./bashScript.bash nameOfProgram < someInputFile #If it is like this we just call the program passing in the input file.


Can anyone explain to me how we determine if there was an input file or not? name of program becomes $1 but I cannot seem to find out how it records someInputFile. Is it even possible to use a redirection in a bash script?
Thanks
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Sep 15 2013 03:25am
When you say is it possible to use redirection in a bash script you are referring to the aforementioned
Code
nameOfProgram < someInputFile
right?

This post was edited by Eep on Sep 15 2013 03:33am
Member
Posts: 8,112
Joined: Sep 23 2006
Gold: 3,558.23
Sep 15 2013 10:06am
I'm not quite clear on what it is you're trying to do, but you can always output the script result to a file and then cat the file to read it back.

In trying to keep it as simple as possible, think of < as importing and > as exporting. This is not always the case, but for this it works. Redirection is very possible, and important!
http://mywiki.wooledge.org/BashGuide/InputAndOutput#Redirection

You could add an error check to see if there was an input file. Adding this line to your script will export any errors to the file "errorcheck".
Code
> done 2> errrorcheck
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll