Hi folks

I am struggling to pass the value of a variable, to be used as an argument for a number of sequentially called python scripts, themselves called from a bash script. Apologies for the pathname chaos.

Phase 1: reads the case names from a text file, line by line, saving the name to $case

#Determine how many cases were run
cd /Users/stuartmuller/Sort/PhD/'Analytical testing'
j=$(wc -l 'cases.txt' | awk '{print $1'})

IFS=$'\n'

#Copy AN output files for each case from VM to HOST and process
for line in $(cat cases.txt)
	do
		case=$line
		#Copt file from VM to HOST machine
                /Library/'Application Support'/'VMware Fusion'/vmrun -T fusion -gu 'Stuart Muller' -gp gandalf copyFileFromGuestToHost /Users/stuartmuller/Documents/'Virtual Machines.localized'/'Windows 7.vmwarevm'/'Windows 7.vmx' 'C:\Program Files\UCR\STANMOD\Projects\3DADE\AN'$case'\CXTFIT.OUT' $scripting'/src/Stu/CXTFIT_'$case'.OUT'
		bash StuANoutputPrep.sh $case 
	done

Phase 2: Call python script

#Read in argument and save to case2
echo case2 = $1
cd $scripting/src/stu
python StuDeleteMultipleLines.py $case2

Phase 3: Run python script using the value of $case2

import sys
case3 = sys.argv[1]
print case3

The printed output for case3 is "sys.argv[1]" - this is not the value of the variable given as the argument (case3=case2=case='some text'), not even the name of the variable as given in the argument (case2 or $case2)

Clearly I am new to this and bumbling me way around in the dark, so any assistance would be awesome :-)

echo case2 = $1

doesn't do any assignment, it just prints stuff.
You need

case2=$1

or just

python StuDeleteMultipleLines.py $1

PS: why not do everything in python?

Hi nezachem

Thanks for the help - haven't dug into it again yet but your suggestion makes obvious sense. I'm afraid I am still very much finding my way with scripting in any language, so while in hindsight it seems like an obvious solution it really was nowhere near being on my radar.

And this really explains why I am not doing this entirely in python. I'm basically trying to muscle my way through a script that is supposed to edit files on a virtual machine, run exes on the VM, post-process data and graph it all... Currently my "script" is a combo BASH-CMD-VBA-PYTHON. Yes. Wtf. My thoughts exactly.

I'm using the VBA to automate the graphing software (Surfer) because that is the language of the examples and I don't know VBA or Surfer. The DOS batch file deletes some old files before executing a BIG Fotran numerical model. I ended up using python for the editing of text input and output files in order to change input values for the model and process output data into a format for Surfer. And then the BASH script is what holds it all together at this point, and is where it all began because the only instructions I could find for accessing the virtual machine were Unix.

I'm hoping to be able to migrate things later, once I have some sort of a clue, so any advice or pointers to good resources would be appreciated.

Long answer - sorry. And thanks again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.