Passing filenames/variables into a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing filenames/variables into a script
# 1  
Old 03-02-2004
Passing filenames/variables into a script

Hi! I'm somewhat new to Unix (I use it to fiddle, but not seriously), and at my work I have come to use it quite a bit. My question is this:

I want to create a script to take the tedium out of repetitious tasks. However, I need to pass a file name into the script in order for it to work.

How would I do that?

Thanks
# 2  
Old 03-02-2004
First, welcome. Please read the rules (Just in case your evil twin is making you ask the question {see home page })

What scripting language are you using, OS and version? Normally, you can pass a variable (filename or other info) in parameters 1 through 8.

example:
$ cat junk
#!/bin/ksh
echo $1
$
$ ./junk newstuff
newstuff
$
# 3  
Old 03-02-2004
I'm running Windows 2000. I'm using an X11 interface called Exceed, and the editor I'm using is the Exceed editor called TextEdit. My shell is the K shell (ksh).

What do you mean by what language? Isn't a Unix script just a set of Unix commands that get executed by the computer rather than me typing them in? The language I'm using is Unix... :\

What I would like to do is something aking to this: (my script is called cdrmln, based on the commands it uses)

$ ./cdrmln{get_profile.cgi}

and then have the code inside cdrmln do stuff based on the name "get_profile.cgi".
# 4  
Old 03-02-2004
Actually, the thing with $1 just solved my problem.

Thank you very much Smilie
# 5  
Old 03-02-2004
Quote:
What do you mean by what language? Isn't a Unix script just a set of Unix commands that get executed by the computer rather than me typing them in? The language I'm using is Unix... :\
You can build a script with different 'languages' (maybe I should have quoted it in the first place). You would actually be using a shell - in your case ksh. You could have been using sh, csh, bash, ... or something like Tcl, Perl. If you don't specify, then we have less information then we need to assist. UNIX is not a language.

Since you are using Exceed, are you connecting to a UNIX based system? If so, then what is that system OS and version (can be found with the uname command {options can be found in the man page - $ man uname }).

If you are using ksh, then the parameters given earlier should work.
# 6  
Old 03-02-2004
Yes, I'm connecting to a server called "flagfish", which runs SunOS 5.8.

The script now works great (using the $1 thingy), but I'm having a bit o' trouble with rm -f, but that should be a quick fix.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing variables from one script to another

Hi, this is the example i'm trying to do. script1.sh ABC="test.txt" ./script2.sh "$ABC" script2.sh INPUT="$HOMEDIR/$ABC" echo $INPUT when i run the 1st script it gives me ../home/ the test.txt is not passed into 2nd script. How can i resolve this. (2 Replies)
Discussion started by: gskris88
2 Replies

2. Shell Programming and Scripting

Passing gnuplot variables to shell script

Hi, I need to pass a gnuplot value to a shell script. I have a main shell script (Main.sh) that has a bunch of gnuplot commands. Main.sh calls another gnuplot script (Child.gnu). A part of the code in Child.gnu is as follows: sp '</data/src/scripts/results/plot_data.sh $col' u (A):2:3 w pm3d... (8 Replies)
Discussion started by: annazpereira
8 Replies

3. Shell Programming and Scripting

passing a variables value from the called script to calling script using ksh

How do i get the value of the variable from the called script(script2) to the calling script(script1) in ksh ? I've given portion of the script here to explain the problem. Portion of Script 1 ============= ----- ----- tmp=`a.ksh p1 p2 p3` if then # error processing fi -----... (10 Replies)
Discussion started by: rajarkumar
10 Replies

4. Web Development

passing variables to python script

Hello again, You guys might remember me from the "Apache problems" thread. And because this forum is the only one that actually helped me out after months of problems I was hoping you could help me with something related. Now if you remember the final code that we made for creating an account... (0 Replies)
Discussion started by: darkphaux
0 Replies

5. Shell Programming and Scripting

Passing data from file to variables for script

Hello all! After searching through numerous helpful posts on these forums I am still having an issue with a task I am trying to accomplish. I am trying to take data from an input file, store the contents as variables, and use the variables in the script. The input file (input.txt) is... (2 Replies)
Discussion started by: screwed718
2 Replies

6. Shell Programming and Scripting

Need help passing variables in shell script to perl one-liner

I'm writing a script to automate some post-install tasks on RHEL4 servers. I need the following code to insert an 'A' in the middle of a string, then replace the string in a file. I know I can use sed to do this, but I'd like to use perl's in place edit so I don't have to write to a temp file,... (1 Reply)
Discussion started by: Xek
1 Replies

7. Shell Programming and Scripting

passing variables to sed function in a script ....

Hello , I have a script named testscript.sh wherein I have two variables $var and $final (both of which contain a number) I have a sed write function inside this script as follows: sed '1,2 w somefile.txt' fromfile.txt Now , in the above i want to pass $var and $final instead of... (2 Replies)
Discussion started by: shweta_d
2 Replies

8. Shell Programming and Scripting

passing two variables into a shell script?

Hello all, i have a infile.txt text file which contains such variables: aaa 123 asds 1323 asdsd 13434 lkjlkj 324324 23432 lkjlkj 24324 ljlkj 3j4lk 234kj3 and i want to pass them to my script such as: ./myscript $1 $2 where $1 is the first value in the first row and $2 is the second... (2 Replies)
Discussion started by: Bashar
2 Replies

9. Shell Programming and Scripting

passing variables to sed inside script

I am trying to pass a regular expression variable from a simple script to sed to remove entries from a text file e.g. a='aaaa bbbb cccc ...|...:' then executing sed from the script sed s'/"'$a"'//g <$FILE > $FILE"_"1 my output file is always the same as the input file !! any... (5 Replies)
Discussion started by: Daniel234
5 Replies

10. Shell Programming and Scripting

passing variables to awk from ksh script

I'm trying to write a ksh script that uses awk, but I want to pass variables to awk. For example (not working): if ];then searchstr=$1 lsof -i | awk '{if($9~/SEARCHSTR/) print $2} SEARCHSTR=$searchstr' else echo "usage: $0 <search string>" fi I tried several options. Is it... (3 Replies)
Discussion started by: rein
3 Replies
Login or Register to Ask a Question