0

This is the first time I am working with shell scripts. Passing one element at a time works. However I have got confused because I have a method which requires a list as an argument and currently, whatever I tried, it just takes the first element of list. But I wish to pass the entire list at one time only.

run.sh

#!/bin/bash
list = 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95;
qsub job.sh "label" $list 

job.sh

#!/bin/bash
python file.py $1 $2

file.py

import sys
import os
from myClass import myClass
label = sys.argv[1]
list = sys.argv[2]
myObject = myClass(label,list)
1
  • You should be able to slice sys.argv -- in other words, something like lst = sys.argv[2:] (try to avoid using list though). Commented Jun 9, 2018 at 12:52

2 Answers 2

3

You need to double quote things with spaces in the shell, and drop spaces around assignments (=)

list="0.1 0.2 24 45"
qsub job.sh "label" "$list"

and

python file.py "$1" "$2"
Sign up to request clarification or add additional context in comments.

Comments

0

Try this

job.sh

#!/bin/bash
python file.py $*

file.py

import sys
import os
from myClass import myClass
label, list = sys.argv[1], sys.argv[2:]
myObject = myClass(label, list)

6 Comments

Thanks for the answer. However I forgot to mention that I have other arguments in the method. By doing $*, it is considering other arguments as well as a part of the list. How should I tackle this..
If your example does not demonstrate what you are asking, noone can help. Trim down the ridiculously long list of numbers (which are not required for stackoverflow.com/help/mcve) and show a better example.
Ok...see revisions
./run.sh: line 12: syntax error near unexpected token list' ./run.sh: line 12: list = 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95;'
You REALLY need to simplify your example. Why are there so many numbers? And why is there a semicolon on the end of the line? Stop and read this stackoverflow.com/help/mcve
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.