Calling programs from different directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Calling programs from different directories
# 1  
Old 10-20-2010
Calling programs from different directories

I have some csh and awk scripts on path

Code:
/nethome/chrisd/HSeis/TommyCD/TommyCD-1101/Scripts

Usually I have a working directory from where I run the scripts by having a soft link to the Scripts directory
in the directory above the working one

For example from

Code:
/nethome/chrisd/HSeis/TimeDistance/TimeDistance-1101/B-rgdt0p25/A-Synt/A-jcdint

I can run a csh program using

Code:
../Scripts/prog.csh

Now, this is where I get confused. prog.csh calls two awk programs like this

Code:
  if (($nAnomaly == 1) && ) then
      awk -v anomaly=$Anom -v zloc="$zmin/$zmax" -v dz=$dz  \
          -v cols=$cols -v maxdepth=$maxdepth               \
          -f $spath/create-anomaly-zc.awk $fref.zc > $fmod.zc
  else if ($nAnomaly == 2) then
      awk -v anomaly="$nAnom/$pAnom" -v zloc="$zmin/$ztran/$zmax"  \
          -v dz=$dz -v cols=$cols -v maxdepth=$maxdepth            \
          -f $spath/create-anomaly-zc.awk $fref.zc > $fmod.zc
  endif

  awk -v xi="$xix/$xiz" -v xf="$xfx/$xfz"  \
      -f $spath/convert-zc-cmod.awk $fmod.zc > $fmod.cmod

As you can see I have included the variable spath which I set to the full path to the awk scipt

Code:
set spath = /nethome/chrisd/HSeis/TommyCD/TommyCD-1101/Scripts

I'm not sure what would be the best way to call the two awk scripts, they are found in the same directory as the .csh file

Last edited by kristinu; 10-20-2010 at 04:48 PM..
# 2  
Old 10-20-2010
It is not beautiful, but it works. Better is the enemy of good enough. Do you have a specific additional need?

You could use $PATH if the awk files are good executables with first line #!/bin/awk -f and the executable chmod/ls -l permissions.

https://www.unix.com/shell-programmin...#post302464588

The .cshrc is usually in $HOME so login sees it, and scripts and data files should not be!

https://www.unix.com/shell-programmin...#post302464505
# 3  
Old 10-20-2010
Apologies, but I am not sure what you mean exactly.

Can you give some example?
# 4  
Old 10-20-2010
Any script whose interpreter can find the script with at most one extra argument, ike ksh or sed -f or awk -f, can be made into a barefoot, freestanding executable with one line and file mode bits.

Any directory in your $PATH is searched for executables by entry name.

Make your awk scripts executable, put them in a application-dedicated bin directory, put that directory in your $PATH, and just call them without the awk, -f, path.

Suppose I was doing something similar:

I type: mkdir ~/bin
and in there I put a file davidx, and in that file I have:
Code:
#!/usr/bin/awk -f

 -- awk commands --

I type: chmod u+x ~/bin/davidx
to add execut for me.

I type: PATH=$PATH:~/bin
and add that line to my: ~/.profile

Now, I can just say this in my shell script david_sh: davidx option1 option2 ...

I should put my shell script david_sh in ~/bin, too. Then, I can call it by just typing entry name david_sh when I test. If it is a ksh script, it should look like:

Code:
#!/user/bin/ksh

 . ~/.profile

 -- ksh script commands --

 davidx option1 option2 ...

 -- ksh script commands --

Your interpreter paths (/usr/bin for ksh, awk) may vary.
# 5  
Old 10-20-2010
There's one problem. I actually go to a different machine, which can see the Scripts and working directories and run everything from there. The thing is that I cannot change stuff on them. Can't use my machine as it's too slow.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

Giving read write permission to user for specific directories and sub directories.

I have searched this quite a long time but couldn't find the right method for me to use. I need to assign read write permission to the user for specific directories and it's sub directories and files. I do not want to use ACL. This is for Solaris. Please help. (1 Reply)
Discussion started by: blinkingdan
1 Replies

2. UNIX for Dummies Questions & Answers

Difference between inbuilt suid programs and user defined root suid programs under bash shell?

Hey guys, Suppose i run passwd via bash shell. It is a suid program, which temporarily runs as root(owner) and modifies the user entries. However, when i write a C file and give 4755 permission and root ownership to the 'a.out' file , it doesn't run as root in bash shell. I verified this by... (2 Replies)
Discussion started by: syncmaster
2 Replies

3. UNIX for Dummies Questions & Answers

List the directories, having given pattern in the directories name, sorted by creation date

It is for HP-Unix B.11.31. Requirement: 1. List the directories, having given pattern in the directories name, sorted by creation date. Example: Directories with name "pkg32*" or "pkg33*" 2. On the output of 1. list the directories by creation date as sort order, with creation date... (2 Replies)
Discussion started by: Siva SQL
2 Replies

4. Shell Programming and Scripting

How to list all the files, directories and sub-directories in the current path except one directory?

Can anyone come up with a unix command that lists all the files, directories and sub-directories in the current directory except a folder called log.? Thank you in advance. (7 Replies)
Discussion started by: Manjunath B
7 Replies

5. UNIX for Dummies Questions & Answers

Using grep command to find the pattern of text in all directories and sub-directories.

Hi all, Using grep command, i want to find the pattern of text in all directories and sub-directories. e.g: if i want to search for a pattern named "parmeter", i used the command grep -i "param" ../* is this correct? (1 Reply)
Discussion started by: vinothrajan55
1 Replies

6. Shell Programming and Scripting

main program is not calling small other programs

I am trying to understand a program in a book and this program suppose to call other programs which are in the same folder, the other programs are called 'lu' and 'add' but for some reason when it gets to the last line of each case to call these programs there is an error message saying ./rolo:... (2 Replies)
Discussion started by: bartsimpsong
2 Replies

7. UNIX for Dummies Questions & Answers

Are programs like sys_open( ) ,sys_read( ) et al examples of system level programs ?

Are the programs written on schedulers ,thread library , process management, memory management, et al called systems programs ? How are they different from the programs that implement functions like open() , printf() , scanf() , read() .. they have a prefix sys_open, sys_close, sys_read etc , right... (1 Reply)
Discussion started by: vishwamitra
1 Replies

8. Shell Programming and Scripting

Script for parsing directories one level and finding directories older than n days

Hello all, Here's the deal...I have one directory with many subdirs and files. What I want to find out is who is keeping old files and directories...say files and dirs that they didn't use since a number of n days, only one level under the initial dir. Output to a file. A script for... (5 Replies)
Discussion started by: ejianu
5 Replies

9. UNIX for Dummies Questions & Answers

help with calling programs

Hi. I have a problem in running a program in linux system. This program (damaver.l86) is in the path /home/shenk/damaver/, and it needs to call another program (supcomb.l86) in another path /home/shenk/supcomb/. I tried to modified the .bash_profile, but it didn't work. The error message is always... (1 Reply)
Discussion started by: shenk
1 Replies
Login or Register to Ask a Question