LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-02-2007, 09:18 AM   #1
vxc69
Member
 
Registered: Jul 2004
Distribution: Ubuntu
Posts: 387

Rep: Reputation: 33
Bash Script: get line input eg: ./myscript -i get_this -o get_this


Hello,

I'm not too good with bash scripting. How do I get input from the user? I've used the read -p before but that won't suffice this time because I need to be able to run the script on one command.

This is my task in detail:

I'm writing a scrip to convert any video file to a FLV type. The script should run from a web browser on the users command.

So the PHP needs to be something like:
Code:
exec(/var/www/myfolder/scripts/vid2flv.sh -i input_file -o output_file);
How do I get the contents after -i and -o into my shell script as separate variables?

EDIT: I've been googling this with no luck, is this even possible? It has to be, otherwise how do those config scripts work?!?!


Thanks,
vxc

Last edited by vxc69; 06-02-2007 at 09:55 AM.
 
Old 06-02-2007, 11:40 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
If you omit the "-i" and "-o" its actually a bit easier.

e.g.
/var/www/myfolder/scripts/vid2flv.sh input_file output_file

In your script input_file would be $1 and output_file would be $2.

If you're doing any functions or sets in your script you probably want to make them named variables so that you don't later use the wrong "positional parameters".

e.g.
INFILE=$1
OUTFILE=$2
echo "The input file was $INFILE and the output file was $OUTFILE."

Note: The above all applies to shell scripting. Haven't done any PHP myself so don't know if your exec syntax is correct for that.

Type "man bash" for more details. Look for positional parameters. Also look for other information such as the meaning of $*, $@ etc... which are built in mechanisms to deal with all the arguments passed in from the command line.
 
Old 06-02-2007, 12:14 PM   #3
vxc69
Member
 
Registered: Jul 2004
Distribution: Ubuntu
Posts: 387

Original Poster
Rep: Reputation: 33
Quote:
Originally Posted by jlightner
If you omit the "-i" and "-o" its actually a bit easier.

e.g.
/var/www/myfolder/scripts/vid2flv.sh input_file output_file

In your script input_file would be $1 and output_file would be $2.

If you're doing any functions or sets in your script you probably want to make them named variables so that you don't later use the wrong "positional parameters".

e.g.
INFILE=$1
OUTFILE=$2
echo "The input file was $INFILE and the output file was $OUTFILE."
This works just fine. Thanks. And also thanks for giving me the right keyword, positional parameters and the man tips.
 
  


Reply

Tags
bash, get, input, line, parameters



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash shell script read file line by line. Darren[UoW] Programming 57 04-17-2016 06:07 PM
Bash multi-line input won't wrap correctly spiffytech Linux - Software 2 03-28-2006 05:37 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
bash-script input aizkorri Programming 7 07-08-2003 06:15 AM
bash: ./myscript: bad interpreter: No such file or directory Stefangeelen Linux - Newbie 3 09-05-2002 01:50 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration