0

I am running a script run.sh. The script is executed as follows. $./run.sh read.csv The contents of the script are as follows.

   tail -n +2 $1 | while IFS="," read -r A B C D E F;
    do
        python test.py ${A} ${B} ${C} ${D} ${E} ${F}
    done

My question is "If i need to pass in additional command line arguments along with read.csv from the terminal like this (for Ex: $./run.sh name sex DOB read.csv) how do i modify the code so that it works fine.

Because if i pass any other command line arguments along with the file name(read.csv) i am getting access errors to the file read.csv

1
  • 1
    Why not just use python to parse csv Commented Oct 11, 2016 at 17:44

1 Answer 1

1

Positional parameters is what you are after. This is how you can do it:

tail -n +2 $4 | while IFS="," read -r A B C D E F;##note now you would pass $4 to tail command which is your file name
do
    python test.py ${A} ${B} ${C} ${D} ${E} ${F}
done

You could access those values like name in $1, sex in $2, DOB with $3 and read.csv in $4

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.