Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 927867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:55:14+00:00 2026-05-15T19:55:14+00:00

In sh: ~$ `echo ls` bin/ Desktop/ But in fish: fish: Illegal command name

  • 0

In sh:

~$ `echo ls`
bin/  Desktop/

But in fish:

fish: Illegal command name “(echo ls)”
~% (echo ls)

(Note that the error message appears above the command line.)

~% echo (echo ls)
ls
~% eval (echo ls)
bin/  Desktop/

fish: Illegal command name “(echo ls)”
exec (echo ls)
     ^
~% exec (echo ls)

It seems that command substitution only works as parameters of a command, not as a command itself? Why?

Well, the help doc does say

If a parameter contains a set of parenthesis, the text enclosed by the parenthesis will be interpreted as a list of commands.

But still, why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:55:15+00:00Added an answer on May 15, 2026 at 7:55 pm

    Update

    This answer was written ten year ago in 2010.
    Recent versions of fish (I tested on 3.1.2) updated and set cmd ls; $cmd is valid now.

    How

    This because command substitutions belong to parameter expansions and are not allowed as commands.

    A similar example:

    in sh:

    tmpls=ls
    $tmpls
    

    But in fish:

    % set cmd ls; $cmd
    fish: Variables may not be used as commands.
    ...
    

    Why

    In short, it’s good for verifiability

    This article explains details:

    Since it is allowed to use variables as commands in regular shells, it is impossible to reliably check the syntax of a script. For example, this snippet of bash/zsh code may or may not be legal, depending on your luck. Do you feel lucky?

        if true; then if [ $RANDOM -lt 1024 ]; then END=fi; else END=true; fi; $END
    

    Both bash and zsh try to determine if the command in the current buffer is finished when the user presses the return key, but because of issues like this, they will sometimes fail. Even worse, this piece of perfectly legal code is rejected by bash:

      FI=fi; foo() { if true; then true; $FI; }
    

    Fish avoids this kind of problem, since variables are not allowed as commands. Anything you can do with variables as commands can be done in a much cleaner way using either the eval command or by using functions.

    For the same reason, command substitutions are not allowed as commands.

    (Note: The cited example is not fair, since ‘if’ and ‘fi’ are not simple commands but reserved words. See comments below.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple script named example : #!/bin/sh echo $'${1}' Please note that
#!/bin/bash echo 'first line' >foo.xml echo 'second line' >>foo.xml I am a total newbie
#!/bin/bash if test $# == 4; then echo $*; else echo args-error >&2; fi;
Why can't the folder be found? I double checked that it exists. #!/bin/bash echo
why does it still produce output in the third command? $cat sh.sh #!/bin/sh echo
I've written this script: #!/bin/bash file=~/Desktop/test.txt echo TESTING > $file The script doesn't work;
What's happening here : $ echo $SHELL /bin/bash $ echo -e foo foo $
I have the following PHONY target in Makefile install: echo /usr/bin/shelldecrypt must be writable
#!/bin/bash echo SCRIPT: $0 echo Enter Customer Order Ref (e.g. 100018) read P_CUST_ORDER_REF echo
For testing purposes I have this shell script #!/bin/bash echo $$ find / >/dev/null

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.