admin管理员组文章数量:1352233
During some cleanup on macOS Monterey, uninstalled and reinstalled gshuf
. Aliased shuf
to gshuf
.
The line from zshrc
:
alias shuf='gshuf'
I have a tool for my music with these three lines as the total file:
shuf -n 1 /Users/joel/sh/tools/keys.txt
shuf -n 1 /Users/joel/sh/tools/timesig.txt
shuf -n 4 /Users/joel/sh/tools/notes.txt
Running the file in the terminal
keys.sh
returns
/Users/joel/sh/tools/keys.sh: line 1: shuf: command not found
/Users/joel/sh/tools/keys.sh: line 2: shuf: command not found
/Users/joel/sh/tools/keys.sh: line 3: shuf: command not found
Other aliases work fine. Restarted terminal, sourced zshrc
, restarted computer. Same error.
Running keys.sh
should return random-ish values from the files keys.txt
, timesig.txt
, and notes.txt
.
During some cleanup on macOS Monterey, uninstalled and reinstalled gshuf
. Aliased shuf
to gshuf
.
The line from zshrc
:
alias shuf='gshuf'
I have a tool for my music with these three lines as the total file:
shuf -n 1 /Users/joel/sh/tools/keys.txt
shuf -n 1 /Users/joel/sh/tools/timesig.txt
shuf -n 4 /Users/joel/sh/tools/notes.txt
Running the file in the terminal
keys.sh
returns
/Users/joel/sh/tools/keys.sh: line 1: shuf: command not found
/Users/joel/sh/tools/keys.sh: line 2: shuf: command not found
/Users/joel/sh/tools/keys.sh: line 3: shuf: command not found
Other aliases work fine. Restarted terminal, sourced zshrc
, restarted computer. Same error.
Running keys.sh
should return random-ish values from the files keys.txt
, timesig.txt
, and notes.txt
.
- Aliases are normally disabled in scripts; they're intended to be used as interactive shorthands, not as general-use commands. Also, if your script doesn't have a shebang, it'll be run with /bin/sh, which (on macOS) is bash, not zsh. – Gordon Davisson Commented Apr 1 at 10:17
- @GordonDavisson: In zsh, this is not switcheable. Aliases are always expanded, in script or interactively. – user1934428 Commented Apr 1 at 10:59
- Using shuf at the command line works. Changing the script to call gshuf works. Seems clear that what I had installed before was shuf, not gshuf, and that in fact the alias was not expanding. I'll use gshuf in scripts and shuf at the command line. Problem solved. – spinhead Commented Apr 2 at 3:01
- user1934428 When all other efforts have failed, I know better than to come asking for help without doing everything, including restarting my computer. Small effort to make to be absolutely sure it won't solve the problem. I don't understand anything in your entire answer, so if you care to give examples to clarify I'd love to learn. For instance, paragraph 2: by 'definitions' do you mean the alias, or something else? Which file is 'this file'? Those answers might clarify the rest of your comment. – spinhead Commented Apr 2 at 3:06
1 Answer
Reset to default 1There is no point in restarting the whole computer just because you want to edit your shell configuration.
If you put the definitions into .zshrc, you have to source this file from your script. How else could zsh then now about them? .zshrc is only sourced automatically from an interactive zsh.
However sourcing .zshrc in a script is in general a bad idea, since this file should contain definitions which are used for interactive shells, and you perhaps don't want all of them in your script. Therefore, I suggest one of two approaches:
Put them into ~/.zshenv . This file is automatically read by every zsh invoked under your user id.
Put them into a separated file, say ~/.zsh_aliases, and source this file from both your .zshrc and your script.
本文标签: macosSpecific new alias failing while existing works (even after restart)Stack Overflow
版权声明:本文标题:macos - Specific new alias failing while existing works (even after restart) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743901716a2558794.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论