Using redirect for input instead of command line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using redirect for input instead of command line
# 1  
Old 05-23-2012
Using redirect for input instead of command line

I have a script that is working when I input parameters from the command line. I was under the assumption that i could use a redirect for the input.

script fred.sh:
Code:
value1=$1
value2=$2
print $value1 $value2

Running from command line:
Code:
fred.sh 1 2 1 2

Contents of file fred.txt:
Code:
1 2

Running from command line:
Code:
fred.sh

Moderator's Comments:
Mod Comment Please don't write it all away in one line and use carriage return/enter. That makes reading texts much easier Smilie Also: Please use code tags, thanks!

Last edited by zaxxon; 05-23-2012 at 09:19 AM.. Reason: not a single line break, code tags
# 2  
Old 05-23-2012
Try

Code:
xargs fred.sh < fred.txt

# 3  
Old 05-23-2012
HI


Code:
$ cat fred.txt
1
2


Code:
$ cat fred.sh
#!/bin/ksh

read value1
read value2
print $value1 $value2


Code:
$ ./fred.sh < fred.txt
1 2

# 4  
Old 05-23-2012
Thanks

Very cool xargs worked perfectly! Was not able to get ./fred.sh to accept input either. Thanks for help guys.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Regarding file input to SQL from command line

Hi friends, Need your help again to get a best approach for the below scenario. I am previously having one shell script which accepts request_id/s as the command line argument. single req_id arg= 1111 Multiple arg= 1111,2222,3333 which gets passed to the embedded sql inside to... (9 Replies)
Discussion started by: Showdown
9 Replies

2. Shell Programming and Scripting

Error to Read Input from command line

Team , I am trying to write a case condition for database backups.But I am unable to make the script to read input from command line . while true ;do read -p "Do You Wish To Take Database Backup ?? " yn case $yn in *) echo " YES take backup ";; *) echo " NO BACKUP " ;; ... (9 Replies)
Discussion started by: rocking77
9 Replies

3. Shell Programming and Scripting

Command line multiple input

I'm using the below to get multiple input from USER and it is working, is there any better way in awk array single liner? echo "Enter Multiple input (Ctrl+d to exit)" >output while read A do echo "$A" >>output done (3 Replies)
Discussion started by: Roozo
3 Replies

4. Shell Programming and Scripting

Redirect output of command line to for loop

I would like to redirect output of command line in for loop as $line. Output should be processed as line but instead it throw whole output. Could somebody help me on how to redirect output of command line and process it line by line without sending output to any file. below is my code ... (1 Reply)
Discussion started by: tapia
1 Replies

5. Shell Programming and Scripting

Is it possible to prompt for input if not given on command line?

I have a script built that takes the standard inputs $1 $2 $3 after the name and parses some data. hexsite=`echo "obase=16;$1"|bc` hexfix=$(printf "%.3X" 0x$hexsite) if || ;then type=33 elif || ;then type=59 elif ;then type=99 else type=00 fi cat /directory/*.2012$3*| I am... (8 Replies)
Discussion started by: PCGameGuy
8 Replies

6. Shell Programming and Scripting

Input variable in command line

i have this script that reads a file "listall_101111" where 101111 varies. awk '{print $0,$1}' listall_101111 | sed -e 's/\(.*\).$/\1/g' | awk '{print $6,$2,$3,$4,$5}' | sort -nrk5 | nawk 'NR==1{m=$5;a++;b=(b)?b:$0;next}$5==m{a++;b=(b)?b:$0}END{for (i in a){print b,a}}' | grep -v ^LG | sort... (4 Replies)
Discussion started by: aydj
4 Replies

7. Shell Programming and Scripting

How to redirect a input of find command into a text file

Hello friends, I want a command to print the reult files from find command into a text file.:) Iam looking from forum memebers. PLZ help me.ASAP Thanks in Advance, Siva Ranganath CH (5 Replies)
Discussion started by: sivaranga001
5 Replies

8. UNIX for Dummies Questions & Answers

redirect stderr and/or stdout to /dev/null from command line

Is it possible to redirect errors at the command line when you run the script such as bash scriptname & 2>/dev/null? (1 Reply)
Discussion started by: knc9233
1 Replies

9. UNIX for Dummies Questions & Answers

Redirect from Variable to command line??

The following creates a needed awk command from some preexisting variables and stores it in the variable i. I then redirect it to a new file change the permission on the file and run it as a script. How can I do a simple redirect on this variable to the command line, instead of creating a new... (8 Replies)
Discussion started by: ugh
8 Replies

10. Programming

using command line input in C code

Hi I need to list files by their size and exclude those that match a certain size. With grep it is easy enough. ll -rt | grep 2166 | awk '{print $9}' 2166 is the filesize and $9 the filenamefield. What should I be looking for to use this in a C program? My aim is to cut the name... (2 Replies)
Discussion started by: vannie
2 Replies
Login or Register to Ask a Question