Please see the following code snippet:
testing(){
local editor="subl -w"
local my_file=~/my_file.md
"$editor" $my_file
}
When running that, I get:
testing:3: command not found: subl -w
What am I doing wrong?
Please see the following code snippet:
testing(){
local editor="subl -w"
local my_file=~/my_file.md
"$editor" $my_file
}
When running that, I get:
testing:3: command not found: subl -w
What am I doing wrong?
You don’t want to quote your editor variable, as currently it’s trying to find an executable with the name ‘subl -w’. a="b c" $a "$a" translates to "b" "c" "b c".
Not quoting the editor variable gives me the same error:
testing:3: command not found: subl -w
What I did was $editor $my_file
If you mean not quoting in local editor=subl -w
then it gives me this error:
testing:local:1: not valid in this context: -w
Really weird. Your code gives me the following:
testing2:2: command not found: subl -w
This is what I have in my bashrc:
testing2(){
a=“subl -w”
$a foo.txt
}
That works for me as well:
testing2(){
a="subl -w"
$a foo.txt
}
testing2
Which version of bash are you using?
Oh, that is interesting. I am using zsh actually. Doing that on a .sh file works fine. Doing that on my zshrc doesn’t.
EDIT: On zsh, you need to do a=(subl -w).