2

I have a scripts (a.py) reads in 2 parameters like this:-

#!/usr/bin/env python

import sys
username = sys.argv[1]
password = sys.argv[2]

Problem is, when I call the script with some special characters:-

a.py   "Lionel"   "my*password"

It gives me this error:-

/swdev/tools/python/current/linux64/bin/python: No match.

Any workaround for this?

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
lionel319
  • 1,180
  • 2
  • 17
  • 31
  • 4
    The quotes should stop the shell from trying to glob the *. What does a.py's shebang line look like, and is python actually installed at /swdev/tools/python/current/linux64/bin/python? – Wooble Aug 23 '11 at 11:59
  • I also cannot reproduce, are you sure the error occurs when reading `sys.argv`? – carlpett Aug 23 '11 at 12:03
  • 4
    Since shell commands may be logged and are viewable by all users on a machine, it's not a good idea to input passwords as command-line arguments. – unutbu Aug 23 '11 at 12:13
  • 3
    Definitely unrelated to python, since python errors never look like that. The shebang (`#!`...) is probably the problem. – Jan Hudec Aug 23 '11 at 12:25
  • Editted the question, putting in the shebang line. Yupe. The python is definitely installed at /swdev/tools/python/current/linux64/bin/python – lionel319 Aug 24 '11 at 01:01
  • i tried removing the shebang line, and instead, call the script thru %python a.py "Lionel" "my*password", still gave me the same error. Any idea what's causing it? – lionel319 Aug 24 '11 at 01:46
  • hey, seems like it is a PYTHON issue. I tried it on a PERL script, it works nicely, but it just doesn't work on a PYTHON script. I really wonder why !! >.< (updated the original question) – lionel319 Aug 24 '11 at 08:20
  • Are you sure this is because of the special character? What happens if you pass an argument that doesn't contain "*"? What happens if you run a simple "Hello world" script with the same shebang? – Tom Zych Aug 24 '11 at 10:00
  • @Tom Zych: no problem. Works fine. It just happens when the '*' is there. – lionel319 Aug 25 '11 at 02:01
  • As indicated by the accepted answer, this is not a reproducible problem as shown; it depends on something being wrong in the command line that was not shown in the question. I have also rolled back an edit to show irrelevant Perl code. This is **not a discussion forum** and questions should never be "updated", but instead *edited* for clarity. The Perl code did not help understand the problem, nor with creating a [mre]. – Karl Knechtel Mar 29 '23 at 00:41

3 Answers3

1

The problem is in the commands you're actually using, which are not the same as the commands you've shown us. Evidence: in Perl, the first two command-line arguments are $ARGV[0] and $ARGV[1] (the command name is $0). The Perl script you showed us wouldn't produce the output you showed us.

"No match" is a shell error message.

Copy-and-paste (don't re-type) the exact contents of your Python script, the exact command line you used to invoke it, and the exact output you got.

Some more things to watch out for:

You're invoking the script as a.py, which implies either that you're copying it to some directory in your $PATH, or that . is in your $PATH. If the latter, that's a bad idea; consider what happens if you cd info a directory that contains a (possibly malicious) command called ls. Putting . at the end of your $PATH is safer than putting it at the beginning, but I still recommend leaving it out altogether and using ./command to invoke commands in the current directory. In any case, for purposes of this exercise, please use ./a.py rather than a.py, just so we can be sure you're not picking up another a.py from elsewhere in your $PATH.

This is a long shot, but check whether you have any files in your current directory with a * character in their names. some_command asd*123 (without quotation marks) will fail if there are no matching files, but not if there happens to be a file whose name is literally "asd*123".

Another thing to try: change your Python script as follows:

#!/usr/bin/env python

print "before import sys"

import sys

print "after import sys"

username = sys.argv[1]
password = sys.argv[2]

This will tell you whether the shell is invoking your script at all.

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
0

That error comes from your shell, not from Python. Do you have a shopt -s failglob set in your .bashrc or somewhere?

Keith
  • 42,110
  • 11
  • 57
  • 76
0

/swdev/tools/python/current/linux64/bin/python: No match.

I think the problem is that the python env is not set:

Does python run at all on your machine ?

fabrizioM
  • 46,639
  • 15
  • 102
  • 119