Sublime Forum

Using 'subl -w' as variable in bash

#1

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?

0 Likes

#2

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".

0 Likes

#3

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

0 Likes

#4

It works for me:

a="subl -w"
$a foo.txt
0 Likes

#5

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
}

0 Likes

#6

That works for me as well:

testing2(){
a="subl -w"
$a foo.txt
}
testing2

Which version of bash are you using?

0 Likes

#7

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).

0 Likes