开发者

Getting bash to ignore bash keywords in a script

开发者 https://www.devze.com 2023-03-09 19:50 出处:网络
I have a script in bash which uses the HTK toolkit. One of the files that the HTK tool uses is called do and is present within a directory called hmm_1/. Now, when I need to call a particular tool fro

I have a script in bash which uses the HTK toolkit. One of the files that the HTK tool uses is called do and is present within a directory called hmm_1/. Now, when I need to call a particular tool from within the HTK toolkit, I do it like so:

some HTK command -H hmm_1/do -H hmm_1/<something else> and so on. I just noticed that gvim highlights the do file name in the above command, thinking it is a keyword. However, it is a file name. My question is:

  1. Will bash interpret it as a keyword or does bash know better (it is just a gvim quirk).
  2. How can I get bash to "know" that some variable names, though innocuously named like keywords are not that and are instead filenames?

Note: I cannot change the name of the file now. I will have to backtrack through a large number of开发者_开发问答 steps.

I just don't know how to phrase this question. Help in editing the question line is most welcome.


As part of a path, keywords will be ignored. They will only be interpreted as a keyword at the beginning of a command. It would be best to simply consider gvim's highlighting to be a minor annoyance and ignore it.


Other than using the command as part of an explicit path (like Ernest proposed, and what will do in your case), you can also use the command builtin to search commands which are in some directory in the $PATH variable, ignoring aliases, shell functions and shell keywords:

$ echo '#!/bin/bash
> echo Hello World!' > ~/bin/do

$ chmod u+x ~/bin/do

~/bin is in my path, thus this would normally work:

$ do
bash: Syntaxfehler beim unerwarteten Wort `do'

It does not, since it is a reserved word. Prefixing it with command helps:

$ command do
Hello World!

As does using the full path:

$ ~/bin/do
Hello World!
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号