LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-04-2020, 03:36 AM   #1
blueray
Member
 
Registered: Feb 2020
Location: Bangladesh
Distribution: Debian, Ubuntu, Linux Mint
Posts: 136

Rep: Reputation: 2
bash command with arguments in variable


If I use export EDITOR="code" then run $EDITOR, It opens vscode.

However, If I use export EDITOR="code -n -w" then use $EDITOR, it says

Code:
% $EDITOR
code -n -w: command not found
How can I use code -n -w in $EDITOR so that it identifies it as a command.
 
Old 08-04-2020, 04:37 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,101

Rep: Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365
what kind of shell is it? in bash it should work that way.
 
3 members found this post helpful.
Old 08-04-2020, 05:13 AM   #3
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,842

Rep: Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221
I think only zsh does not further expand $variables, so $EDITOR behaves like "$EDITOR".
But zsh does further expansions on ${=EDITOR} or short $=EDITOR
 
2 members found this post helpful.
Old 08-04-2020, 06:12 AM   #4
Geist
Member
 
Registered: Jul 2013
Distribution: Slackware 14 / current
Posts: 442

Rep: Reputation: 196Reputation: 196
Quote:
Originally Posted by blueray View Post
If I use export EDITOR="code" then run $EDITOR, It opens vscode.

However, If I use export EDITOR="code -n -w" then use $EDITOR, it says

Code:
% $EDITOR
code -n -w: command not found
How can I use code -n -w in $EDITOR so that it identifies it as a command.
If you want to use it more or less universally, make an alias, if your use case allows it.

Otherwise, as the others stated, tell us your shell, because, zsh, for example, indeed does not do it that way you want it (but it does if you use MadeInGermany's approach), and bash, indeed, does do it the way you want to.

Last edited by Geist; 08-04-2020 at 06:13 AM.
 
Old 08-04-2020, 08:31 AM   #5
blueray
Member
 
Registered: Feb 2020
Location: Bangladesh
Distribution: Debian, Ubuntu, Linux Mint
Posts: 136

Original Poster
Rep: Reputation: 2
I am actually using zsh.
 
Old 08-04-2020, 08:34 AM   #6
blueray
Member
 
Registered: Feb 2020
Location: Bangladesh
Distribution: Debian, Ubuntu, Linux Mint
Posts: 136

Original Poster
Rep: Reputation: 2
I am currently using

Code:
export VISUAL=(code -n -w)
export EDITOR=(code -n -w)
Not sure whether it is a good idea or not.
 
Old 08-04-2020, 09:08 AM   #7
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,842

Rep: Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221
Quote:
Originally Posted by blueray View Post
I am currently using

Code:
export VISUAL=(code -n -w)
export EDITOR=(code -n -w)
Not sure whether it is a good idea or not.
Not good. The parentheses force an array. You need to expand/run it like this:
Code:
${EDITOR[@]}
Simple variable:
Code:
export EDITOR="code -n -w"
# expand/run with
$=EDITOR
Perhaps you can use an alias or function?
Code:
alias code="code -n -w"
# expand/run with
code

Last edited by MadeInGermany; 08-04-2020 at 09:09 AM.
 
1 members found this post helpful.
Old 08-04-2020, 09:18 AM   #8
blueray
Member
 
Registered: Feb 2020
Location: Bangladesh
Distribution: Debian, Ubuntu, Linux Mint
Posts: 136

Original Poster
Rep: Reputation: 2
Thank you very much.
 
  


Reply

Tags
bash, zsh



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
-bash: HISTSIZE: readonly variable -bash: HISTFILESIZE: readonly variable deathsfriend99 Linux - Newbie 4 12-08-2009 12:51 PM
environ variable and command line arguments vtn Linux - Newbie 5 08-16-2009 07:11 PM
bash script - variable arguments indikabandara19 Linux - Newbie 4 05-21-2007 10:40 PM
BASH Script: variable values referencing for console arguments sadarax Programming 1 11-14-2005 05:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration