Pass file as one of argument in shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pass file as one of argument in shell
# 1  
Old 10-20-2013
Pass file as one of argument in shell

Hi,

Is there any way that we can pass one file as one of the argument in shell script ?
# 2  
Old 10-20-2013
Sure...

Script.sh
Code:
#!/bin/sh
thatfile="$1"
echo "Filename: $thatfile"

And call it with: Script.sh FILENAME
Which will output:
Code:
Filename: FILENAME

Hope this helps, gn8
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass each line of a text file as an argument to a command?

I'm looking to write a script that takes a .txt filename as an argument, reads the file line by line, and passes each line to a command. For example, it runs command --option "LINE 1", then command --option "LINE 2", etc. I am fetching object files from a library file, I have all the object file... (2 Replies)
Discussion started by: Paul Martins
2 Replies

2. Shell Programming and Scripting

How to pass Oracle sql script as argument to UNIX shell script?

Hi all, $ echo $SHELL /bin/bash Requirement - How to pass oracle sql script as argument to unix shell script? $ ./output.sh users.sql Below are the shell scripts and the oracle sql file in the same folder. Shell Script $ cat output.sh #!/bin/bash .... (7 Replies)
Discussion started by: a1_win
7 Replies

3. UNIX for Dummies Questions & Answers

How to pass command line argument in shell script?

I need to write a shell script, when I run that script I should pass those arguments if not, then script should not run and pass the error message like invalid option - - should pass the argument. and Exit from the script (8 Replies)
Discussion started by: Nsharma3006
8 Replies

4. Shell Programming and Scripting

How to pass command line argument in shell script?

I need to write a shell script, when I run that script I should pass those arguments if not, then script should not run and pass the error message like invalid option - - should pass the argument. and Exit from the script https://www.unix.com/images/misc/progress.gif (1 Reply)
Discussion started by: Nsharma3006
1 Replies

5. Shell Programming and Scripting

How we can pass the argument when calling shell script from perl script

Can someone let me know how could I achieve this In one of per script I am calling the shell script but I need to so one thing that is one shell script call I need to pass pne argument.In below code I am calling my ftp script but here I want to pass one argument so how could I do this (e.g:... (5 Replies)
Discussion started by: anuragpgtgerman
5 Replies

6. Shell Programming and Scripting

Need to pass argument

Hi, I need to pass the argument in my shell script as db_ubackup20111015*.log Scenario: I have backup log file location in /home/backup directory (more than 40 days). I need to check the log file of the latest one (tail . a. How I can retrieve the latest value other than passing... (1 Reply)
Discussion started by: prashanth_gs
1 Replies

7. Shell Programming and Scripting

How to pass multiple file types search pattern as argument to find?

How can I pass $var_find variable as argment to find command? test.sh var_find=' \( -name "*.xml" -o -name "*.jsp" \) ' echo "${var_find}" find . -type f ${var_find} -print # Below statement works fine.. I want to replace this with the above.. #find . \( -name "*.xml" -o -name... (4 Replies)
Discussion started by: kchinnam
4 Replies

8. Shell Programming and Scripting

how to pass argument remotely

If I run the following command remotely after ssh than it works fine su - oracle -c "/oracle/product/102/db/bin/dbshut" But If I run the following command it doesn't work su - oracle -c "/oracle/product/102/db/bin/lsnrctl stop" Because I think there is a space is present between lsnrctl and... (1 Reply)
Discussion started by: madhusmita
1 Replies

9. UNIX for Dummies Questions & Answers

Pass argument to function

Hi, Can someone please explain to me how I can get a function to recognize a file given as an argument to a script. Suppose the script has the argument as follows: sh script file and the function is as follows: function display_file () { cat $1 } and it s then called #main program... (1 Reply)
Discussion started by: Knotty
1 Replies

10. UNIX for Dummies Questions & Answers

pass argument to a filename

How can I use the value of an argument as a filename? Example: The argument for a process is 999. I would like the output of the process to be placed in a file called 999. I have tried using $$1, but that only assigns a unigue number. thanks JP (1 Reply)
Discussion started by: jpprial
1 Replies
Login or Register to Ask a Question