Results 1 to 3 of 3
I'm fairly new to scripting and I'm trying to create a batch script to run another script. I've copied these scripts from others which work and have modified them, but ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 10-09-2012 #1Just Joined!
- Join Date
- Oct 2012
- Posts
- 2
Problem setting arguments in script
I'm fairly new to scripting and I'm trying to create a batch script to run another script. I've copied these scripts from others which work and have modified them, but I've got a problem with the input arguments not being recognised properly. The scripts are written in csh. The script setup is:
Script to run batch:
#!/bin/csh -f
foreach file (`cat /files/file_list.txt`)
set name = `echo $file | awk '{print substr($1,1,14)}'`
set scale = `echo $file | awk '{print substr($1,16,3)}'`
/folder/scripts/process.csh $name $scale
end
The file_list.txt contains the list of files which need to be processed and a scale # that's required. Each row contains the info for each file.
If I echo the $name and $scale, they come up properly.
The process.csh script:
#!/bin/csh -f
if ($#argv < 2) then
cat << End_Usage
Usage: process.csh <name> <scale>
name: name of data file (.dat file)
scale: scale interval (#)
End_Usage
exit 1
else if ($#argv == 2) then
set input=$1
set int=$2
set output_file=out_$1
endif
endif
....rest of script
Initially I created the scripts with just the $name argument and it worked, but found later that I also needed the $scale argument.
After adding the $scale argument, it isn't recognised properly and the process.csh script tries to use this argument for $input instead of $int.
I'm not sure what's wrong with the script, its probably a simple fix, but I can't work it out! Any advice would be appreciated!
- 10-09-2012 #2Just Joined!
- Join Date
- Oct 2012
- Location
- Delhi, India
- Posts
- 19
did you try to quote the args
try
set name = `echo '$file' | awk '{print substr($1,1,14)}'`
notice the quotes around file
- 10-09-2012 #3Just Joined!
- Join Date
- Oct 2012
- Posts
- 2
I tried it and it didn't work. It displays the message related to < 2 arguments.
okay, managed to fix it. I recreated the text file in a different format (replaced spaces with commas) and that solved the problem.Last edited by sar26; 10-09-2012 at 10:48 PM.


Reply With Quote
