Use -v to pass env variables to ask. Example:

#!/bin/sh

export SGE_TASK_ID=2

awk -v task_id=$SGE_TASK_ID 'NR==task_id' "/tmp/fileList.txt"

Where /tmp/fileList.txt has lines:
1
2
3

[rayson@computer ~]$ ./sh
2

Rayson



On Mon, Apr 16, 2012 at 11:46 PM, Sara Rolfe <[email protected]> wrote:
> Hello,
>
> I have a list of jobs with arbitrary inputs which I would like to submit.  I
> wanted to try and get around the sequential argument requirement by reading
> the input arguments from a text file using:
>
> $infile=$(awk "NR==$SGE_TASK_ID" /myPath/fileList.txt)
>
> However, when I try echo "$infile" it is blank.  I realized that I needed to
> escape the variables in my script, and this is causing me problems.  I can
> get the correct output from awk using:
>
> awk "NR==\$SGE_TASK_ID" /myPath/fileList.txt
>
> And I can correctly assign $infile if I hard code the line number like:
>
> infile=$(awk "NR==1" /myPath/fileList.txt)
>
> So I think I have boiled down the problem to getting the command
> substitution to handle the escape, since just adding the escape to the first
> version does not work. I also attempted to use awk's variable passing:
>
> infile=$(awk -v "line=/$SGE_TASK_ID" 'NR == line' /myPath/fileList.txt)
>
> But this produced the same blank output to echo \$infile (I needed to escape
> this variable too).  I would appreciate any advice on how to get the escaped
> variables to be handled properly or on why my variables need to be escaped.
> Examples that I've seen from other users on my compute cluster use escaped
> variables, but I've noticed that many other examples on line do not.  I'd
> like to understand why I need to use them and if there's any way around it.
>
> Thanks,
>
> Sara
>
>
>
>
>
>
> _______________________________________________
> users mailing list
> [email protected]
> https://gridengine.org/mailman/listinfo/users
>

_______________________________________________
users mailing list
[email protected]
https://gridengine.org/mailman/listinfo/users

Reply via email to