function parameter issue

hi,
i have a function say "mask". i'm passing parameters to the function like file_name \$1 |.
inside the function i'm naming the second parameter as position (i.e value of position will be "$1").
i'm passing the position's value like " $position=a[$position]"
But it is nor picking the value "$1". Instead, while executing it just goes as $position itself.
Please help.

Please tell us what shell/language you are using. Also please show an excerpt of your code since there are things unclear from your description (at least for me), thanks.
When doing so, use

```text
 and 
```

tags to enhance readability and preserve formatting, thanks.

i'm using ksh.

the below is my code. i'm not able to retrieve the "position" value.

function mask
{
   set -x
   file_name=$1
   position=$2
   separator=$3
 
   if [ -e $file_name ];then
      awk '
         BEGIN {FS="[,\|]"}
         FNR==NR{a[$1]=$2;next}
         {if ($position in a) {$position=a[$position];print}
            else print}
      ' OFS="$separator" $DIR_FEEDBASE/GEID_lookup.txt $file_name > $file_name_tmp.dat
      mv $file_name_tmp.dat $file_name
   fi
}

The parameters which will be passed to the function will be like " mask <file_name> \$1 |

  • Not escaping the | when handing it over as parameter of your function will not work, as it is a special symbol in the shell to pipe output from stdout to stdin of the next command. You should try escaping it or putting double quotes around it. You did escape the $ of $1 so why not do the same with the pipe?! :slight_smile:
  • $position is a variable not known/defined in awk. You might want to use something like awk -v position=$position ... to pass it to awk.

After correcting those, try again and let's see if it get's stuck again.

hi zaxxon,
no luck.even now it is not picking the value.

Without having the input files available and the actual code of your function, it is not easy to recreate your problem.
Did you just try to print out the values inside awk? You should try to check out, at which point the values are not the ones you expect.