[SOLVED] <<EOT to program in different directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [SOLVED] <<EOT to program in different directory
# 1  
Old 12-06-2011
[SOLVED] <<EOT to program in different directory

Hello, I am new to shell scrip. I have written a .sh file that goes
Code:
 ./myprogram << EOT
14
file.name
EOT

and works as expectecd - it passes 14 and file.name to the program being run as it askes for command line input. When I try and keep myprogram in a different directory and do the same thing I use
Code:
 PROGRAMS=$HOME/here/lives/code 
$PROGRAMS/myprogram << EOT
14
file.name
EOT

myprogram launches fine, but the variables 14 and file.name are not passed to myprogram as they were before. I am afraid I am stumped, and do not seem to be able to find the answer, but I suspect is is because I do not know the right terms to search for to solve this. Any help would be wonderful Thanks Jimbo
# 2  
Old 12-06-2011
What Operating System and version are you using?
What Shell are you using?

The script looks ok in Posix Shell.
# 3  
Old 12-06-2011
Quote:
Originally Posted by jimbo_cambridge
Hello, I am new to shell scrip. I have written a .sh file that goes
Code:
 ./myprogram << EOT
14
file.name
EOT

and works as expectecd - it passes 14 and file.name to the program being run as it askes for command line input. When I try and keep myprogram in a different directory and do the same thing I use
Code:
 PROGRAMS=$HOME/here/lives/code 
$PROGRAMS/myprogram << EOT
14
file.name
EOT

myprogram launches fine, but the variables 14 and file.name are not passed to myprogram as they were before. I am afraid I am stumped, and do not seem to be able to find the answer, but I suspect is is because I do not know the right terms to search for to solve this. Any help would be wonderful Thanks Jimbo
Maybe myprogram behaves differently if it is run from a different directory. Try running myprogram interactively from the command line using:

Code:
$HOME/here/lives/code/myprogram

Does it behave the same way as it does if you run:

Code:
cd $HOME/here/lives/code
./myprogram

# 4  
Old 12-06-2011
@mobitron
Good thinking.
Perhaps the parameter "file.name" needs the full path if "file.name" resides in $HOME/here/lives/code .
Issuing the "cd" first is a better idea.
# 5  
Old 12-06-2011
right, solved

Everyone, thanks for the quick replies

so, I ran

Code:
-------------------- 
#!/bin/sh 

P=/bin 

$P/cat << EOT 
hello 
world 
EOT 

cat << EOT 
hello 
world 
EOT 
-------------------- 
And I get the output: 
-------------------- 
>./test.sh 
hello 
world 
hello 
world 
> 
--------------------

which is as expected, so looked harder at the code and mobitron hit it on the head. The problem was an issue overwriting files in that directory (hardcoded rather than user permissions which is why I dismissed it and assumed my scripting was at fault). Simple line of code and all fixed

Thanks for the help, without your suggestions I would still be banging my head against a wall!

Jimbo
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

[Solved] No tty present and no askpass program specified!

Hi Guys, I use a script sdcmdeploy.ksh to deploy java application to respective dev/test environment. This script is being executed on SunOS. These apps are weblogic apps & the script internally calls weblogic deploy script to deploy application to weblogic cluster. But at this point it... (2 Replies)
Discussion started by: raj100
2 Replies

2. Shell Programming and Scripting

[Solved] Usage of shell commands inside a C program

Hi I have a program int main(int srgc, char *argv) { for(int i=1; i<50; i++) { system("dd if=/dev/zero of=file$i bs=1024 count=$i"); } return 0; } My doubt is how to use the "$i" value inside C code Please help (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

3. Shell Programming and Scripting

[Solved] Run multiple commands in invoked program

Hi, I have coded a program in Haskell using the compiler Hugs and the program requires multiple commands (with parameters) to be entered into it, it then outputs the result of its execution. I need to test a lot of different options (i.e. the parameters) so it would be obvious to automate the... (0 Replies)
Discussion started by: tz742
0 Replies

4. UNIX for Dummies Questions & Answers

[Solved] Finding the latest file in a directory

Hi All, I am using the below command to find the latest file in a dir: ls -tr $v_sftphomedir/$v_sourcefile |tail -1 or ls -t1 $v_sftphomedir/$v_sourcefile |head -1 and the outpur returned is below: /home/cobr_sftp/var/controllingload/Backup/Dbrwds_Div_1796050246.txt I need only the... (5 Replies)
Discussion started by: abhi_123
5 Replies

5. Fedora

[Solved] Unable to start Matlab program

hello everyone, I have Matlab installed on Fedora 16. I tried running it by simply typing on terminal: $ matlabBut it returned the follwoing error: --- can anyone suggest a solution? cheers, peter ---------- Post updated at 10:57 PM ---------- Previous update was at 10:54 PM ----------... (1 Reply)
Discussion started by: peter_071
1 Replies

6. UNIX for Dummies Questions & Answers

[Solved] take name of directory and files as variables

hi, want to create script that takes name of directory and all files and will copy each file to new directory. then fix errors like files do not exist or no permission to create new directory... these what I have so far... #!/bin/sh dir=~/Documents/Scripts/Copy for i in $(pwd) $(ls)... (23 Replies)
Discussion started by: me.
23 Replies

7. HP-UX

[Solved] /var directory in HP-UX is showing 95%?

Hi Everyone, My var directory is showing near to 100% ? What are the files should i delete to make it less?? Kindly suggest # bdf -i Filesystem kbytes used avail %used iused ifree %iuse Mounted on /dev/vg00/lvol3 1048576 107616 933616 10% 3342 29394 10% /... (10 Replies)
Discussion started by: yadvinder
10 Replies

8. UNIX for Dummies Questions & Answers

Cygwin not waiting for program in background (solved)

Hello, I know this isn't exactly a Unix question, but I wasn't able to find much information elsewhere. I'm trying to run a program in the background using Cygwin on a Windows machine, then use the wait command to pause before proceeding. Unfortunately, as I've confirmed using ps aux, the... (0 Replies)
Discussion started by: ocdcollector
0 Replies

9. Shell Programming and Scripting

Command <<EOT ?

I saw someone use this line and sometimes I see it interchanged with EOF which I understand to mean end of file. What is the purpose of this usage? cat something <<EOT something else EOT (2 Replies)
Discussion started by: glev2005
2 Replies
Login or Register to Ask a Question