Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Question 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

    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 (#)
    exit 1
    else if ($#argv == 2) then
    set input=$1
    set int=$2
    set output_file=out_$1
    endif 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!

  2. #2
    Just Joined!
    Join Date
    Oct 2012
    Delhi, India
    did you try to quote the args

    set name = `echo '$file' | awk '{print substr($1,1,14)}'`

    notice the quotes around file

  3. #3
    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.

  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts