Visit Our UNIX and Linux User Community


Giving input to a script through a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Giving input to a script through a script
# 1  
Old 08-12-2005
Giving input to a script through a script

/home/adw/a.ksh << EOF
a
b
EOF

This is how we give input to a file through script
Our client has done the coding in a different way :-

/home/adw/a.ksh << **
a
b

Can nybody pls tell me the significance of **
# 2  
Old 08-12-2005
Just assigns a wildcard to accept any input as the input file...

In your case it is waiting for 2 files.
# 3  
Old 08-12-2005
Quote:
Originally Posted by Kelam_Magnus
Just assigns a wildcard to accept any input as the input file...

In your case it is waiting for 2 files.
Waiting for 2 files? What does that mean?

My experiments with ksh on HP-UX show that ** in this case is treated exactly like EOF. The shell will read input until the line with ** is reached. No wildcard expansion seems to be done. This is a really odd syntax though. Other shells might behave differently.
# 4  
Old 08-12-2005
I think that it would be a good idea to *not* use any shell wildcards (such as *, ?, etc.) in the input redirection. Better stick to normal characters. I prefer using '!'.
# 5  
Old 08-12-2005
Quote:
Originally Posted by Perderabo
My experiments with ksh on HP-UX show that ** in this case is treated exactly like EOF. The shell will read input until the line with ** is reached. No wildcard expansion seems to be done. This is a really odd syntax though. Other shells might behave differently.
It works the same way as described by Perderabo for Solaris with sh, ksh, bash, csh and tcsh.
# 6  
Old 08-12-2005
For every Bourne-derived shell I know of, concerning the redirection constructs, >, <, >>, and <<, the name supplied after the redirection operator undergoes variable/command/arithmetic/filename expansion/substitiuon, EXCEPT for the case of <<, the "here document" construct. In this case << name, name does NOT get expanded in any way, and so it is treated like a "label" (ie, like in goto statements.) Thus in << **, since no filename expansion occurs, this is just telling the shell to send the following text to the standard input of the command, until a line containing only ** is reached.
But you could use > * (or > $MYFILE), and this will undergo filename (or variable) expansion, so that output will be redirected to the non-hidden file in the current working directory. (If more than one filename would result from filename expansion in a redirection statement like this, different shells will do different things --- read your shell's docs. E.g., bash will throw an arror and not do anything at all. pdksh will treat the glob pattern as a literal text if it matches more than one file (i.e., creates a file with * or ? in its name); otherwise if only one file matches, it will do filename expansion as expected. Both shells will treat the pattern as literal text if does not match any file at all. But for all shells, at least globbing will be attempted, and if one file matches, redirection will occur as expected.)

ALSO: An important point about here documents: The lines in the here doc (ie, those after the line with << name) are NOT treated as literal text, except if name is quoted in some way. If unquoted, the here-doc text is treated essentially like double quoted text on the command line, i.e., undergoes variable/command/arithmetic expansion/substitution (but not filename/tilde/brace expansion). So if, e.g., you want to feed a literal '$USER' to the command, and not the value of this variable, use:
mycomm << 'EOF' (or "EOF"), and not simply mycomm <<EOF.
(On the other hand, if you do use <<EOF, neither '$USER' nor "$USER" in the here-doc will escape getting expanded, but \$USER will. You can use this last approach if your here doc needs some stuff to get expanded, but other stuff to be escaped.)

Last edited by hadarot; 09-03-2005 at 12:33 AM..
# 7  
Old 08-16-2005
So u all mean to say that

/home/adw/a.ksh << **
a
b

only this will not work i'll have to use

/home/adw/a.ksh << **
a
b
**

So here ** is just like any other label

Previous Thread | Next Thread
Test Your Knowledge in Computers #601
Difficulty: Medium
Consider the Unix command sequence ps aux | grep -iv apache2 | wc -l This command will output the total number of apache2 processes running.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script not giving o/p

Hi Below is snippet from script which is not giving the o/p.script name is alarm.sh #!/bin/sh out=`awk '(NR>1) {print $9;exit}' alarm` echo $a however when i simply run the above command i an getting the o/p $ out=`awk '(NR>1) {print $9;exit}' alarm` $ echo $a 6... (2 Replies)
Discussion started by: scriptor
2 Replies

2. Shell Programming and Scripting

Giving Input in a script

Hi, I am a newbie to scripting. I want to know something..Is there any way that I can do this? Here is the thing.. there are so many printer queues in which i need to change a certain option.. am using the hppi utility and i need to modify the printer configuration individually going to each... (3 Replies)
Discussion started by: aksijain
3 Replies

3. Shell Programming and Scripting

Giving automatic multiple Input to a tool from shell script

Hi, Please help me,its urgent. I have a tool that i want to run from a shell script. When we run the tool it will ask the user choice to add or delete. When user enter the choice it will then ask how many units he want to delete or add and will add or delete accordingly. Now I want to... (1 Reply)
Discussion started by: saket18@ymail.c
1 Replies

4. Shell Programming and Scripting

$0 not giving script name

Why does $0 return the word usage rather than the script name when used in a function? Baffeled on this one, any help appreciated. usage() { echo "$0 -cs <number of batches>\n" echo "$0 -c 4" echo "$0 -s 4" # echo "-c = Create" # echo "-s = Submit\n" exit 1 } $... (1 Reply)
Discussion started by: nhatch
1 Replies

5. Shell Programming and Scripting

My script is not giving result for 2 or more arguments

Hi, I am new to shell scripting and my below script is not giving result for 2 or more arguments. Can anyone help pls. #!/bin/sh sname=$(basename $(readlink -nf $0)) echo "This is $sname, running at $(date)" echo "It is running on $(hostname)" echo "Script being run by" echo " User... (3 Replies)
Discussion started by: baigmd
3 Replies

6. Shell Programming and Scripting

giving input to a python wch has been called frm shell script....urgent

i'm calling a python script from shell script. the python needs Y as an input everytime. how can i giv it thru shell script. I tried below code for arg in `cat erd_gen_list.lst` do generateErdSql.py -S $arg << Y done This is giving me err : `<<' unmatched pls help. (1 Reply)
Discussion started by: vini
1 Replies

7. UNIX for Advanced & Expert Users

script giving error

Hi All, i have an small issue... echo " " eval x=$@ export x=`echo $x` echo $x ssh user@ipadrss; cd /mbbv/home/; cd /mbbv/home/orange/orange/ echo pwd bash samplescript.sh $x above is my script which will triger from server A and will connect to server B for some... (2 Replies)
Discussion started by: Shahul
2 Replies

8. Shell Programming and Scripting

script not giving the desired output

Hi, I have a script in which an entry like this ..... FILENAME_B="PIC_${DATE}0732*.JPG" The script connects to an ATM and pull a pic file from it.The format for the file is like PIC_2008061400000001.JPG in the ATM. Means 1st 8 digit is the date(YYYYMMDD) field 2nd 8 digit means hrs... (2 Replies)
Discussion started by: Renjesh
2 Replies

9. Shell Programming and Scripting

Giving input to a c++ file

My C++ program creates a nxn matrix with given value. For e.g if the input is 10 it will creates a matrix of 10x10 now what i want is the script should run program and give input values in a variation of 1000. Say first matrix of 1000 then 2000 , 3000 ..... 10000. I tried using for loop but unable... (2 Replies)
Discussion started by: tonyaim83
2 Replies

10. Shell Programming and Scripting

Giving input through script

Script 1.ksh ========= /home/adw/a.ksh << ** a b Script 1.ksh is working fine even without ending "**" Script 2.ksh ========= if then /home/adw/a.ksh << ** a b fi But the script 2.ksh is giving error "syntax error : `<<' unmatched". Is it bcoz of fi. (1 Reply)
Discussion started by: radhika03
1 Replies

Featured Tech Videos