1

I am trying to pass two directories to my python script which just prints out the directory. But somehow its not working. Below is the code

shellscript.sh:

set VAR1=$(pwd)
echo $VAR1
set VAR2=$(pwd)
echo VAR2
python.exe mypython_script.py "$VAR1" "$VAR2"

mypython_script.py:

import os
import sys

if __name__ = '__main__':
    print(sys.argv[1])
    print(sys.argv[2])

The echo is printing the path, but the terminal also does print the script call line. There its showing python.exe mypython_script.py '' '' and then print statements are printing empty string. Could anyone point out to me where the problem is? Thank you

6
  • Are you sure you should call python.exe instead of only python? Commented Jul 20, 2017 at 17:28
  • @LukasIsselbächer Yea. the script is running but printing empty string Commented Jul 20, 2017 at 17:31
  • 1
    Remove the set command. So you should have VAR1=$(pwd). Commented Jul 20, 2017 at 17:31
  • 1
    I got it working by using just python no .exe and then getting rid of set as was suggested, so just make it python and then no set and it should run fine. Commented Jul 20, 2017 at 17:32
  • bash for windows maybe? Commented Jul 20, 2017 at 17:34

1 Answer 1

3

Your problem is with

set VAR1=$(pwd)

You should use

VAR1=$(pwd)

instead.

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

6 Comments

You also don't need to run pwd; bash already has a shell parameter PWD that expands to the name of the current working directory. Setting VAR1 is redundant.
Hello everyone, thank you all for your valuable inputs. As mentioned in the answer section, after removing SET identifier the script is working fine. :)
Additionally i would like to know that is there a possibility that i can stop the terminal from displaying the arguments for the script. Because the path is very long and it is not necessary.
Isn't the terminal displaying the path because of the echo commands? Remove those to stop displaying them?
Also, it's worth noting that in bash, set is used to set and unset values of shell options and positional parameters (not for assigning values to variables).
|

Your Answer

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