Prevent expansion of wildcards in non-quoted python script argument when running in UNIX environment

前端 未结 4 373
囚心锁ツ
囚心锁ツ 2021-01-14 20:26

I have a python script that I\'d like to supply with an argument (usually) containing wildcards, referring to a series of files that I\'d like to do stuff with. Example here

4条回答
  •  粉色の甜心
    2021-01-14 21:12

    Here is an example for the Bash shell that shows what @Tom Wyllie is talking about:

     alias sea='set -f; search_function' 
     search_function() { perl /home/scripts/search.pl $@ ; set +f; } 
    

    This defines an alias called "sea" that:

    1. Turns off expansion ("set -f")
    2. Runs the search_function function which is a perl script
    3. Turns expansion back on ("set +f")

    The problem with this is that if a user stops execution with ^C or some such then the expansion may not be turned back on leaving the user puzzling why "ls *" is not working. So I'm not necessarily advocating using this. :).

提交回复
热议问题