I have a python script that takes some inputs as arguments. I bash script I want to provide those inputs. here is the input syntax :
usage: 0ドル <virtualenv-dir>
<cairo-dir>
<file-path>
[--server <es-server>]
[--port <es-port>]
[--fields <columns to be uploaded. Comma separated list of columns]
[--filter <ES filter to use>]
[--from-time <start time>]
[--to-time <end time>]
[--timestamp-field <name-of-timestamp-column>]
<index-name>
<recipients-separated-by-comma>
<output-file-name>
I want to learn how to assign these inputs to variable in a bash script and pass the variables to python script.
I tried these :
VIRTUAL_ENV=1ドル
CAIRO=2ドル
PYTHON_FILE_SCRIPT=3ドル
INDEX=4ドル
MAIL_LIST=5ドル
FILE_OUTPUT=6ドル
shift
shift
# Activate virtual environment
source $VIRTUAL_ENV/bin/activate
# Set PYTHONPATH
export PYTHONPATH=$UBUNTU
cd $UBUNTU
# a cronjob to collect the data from the device
python 3ドル 4ドル 5ドル 6ドル
1 Answer 1
The python command seems incorrect: you already called shift, so 3ドル, which is the python script, is now 1ドル.
Replace the last line with
python "$PYTHON_FILE_SCRIPT" "$INDEX" "$MAIL_LIST" "$FILE_OUTPUT"
and you should be just fine.
If you want to perform options parsing, I would suggest you use a while loop and shift arguments while parsing. You can use a case to match options easily. Example:
VIRTUAL_ENV="1ドル"
CAIRO="2ドル"
PYTHON_FILE_SCRIPT="3ドル"
while true; do
case "1ドル" in
--server)
SERVER="2ドル"
shift 2
;;
--port)
PORT="2ドル"
shift 2
;;
# add other cases
*)
break
;;
esac
dome
INDEX=4ドル
MAIL_LIST=5ドル
FILE_OUTPUT=6ドル
# then do what you need to do
VIRTUAL_ENV="1ドル",cd "$UBUNTU",python "3ドル" "4ドル" "5ドル" "6ドル"...). When you "tried these", what problem did you encounter?[email protected]is the second address in the list. Since you don't quote the input, there's no way of knowing that[email protected], [email protected] outputfile.txtis supposed to be two email addresses separated by a comma or one email address (ending in a comma) followed by an outputfile named[email protected].