What's the difference between using shell command (e.g. foo) directly and using $(foo)?

Sol Alsvid

I get confused about using command directly and using $(foo). I'm using Mac, I try to list apps which is install by brew cask(a package manager), and echo each app. I have two short Shell scripts, first one like this:

#!/bin/bash
apps=$(brew cask list)
for app in ${apps}
do
    echo  "${app}"
done

It works fine, however another likes this:

#!/bin/bash
apps=$(brew cask list)
myecho=$(echo)
for app in ${apps}
do
    ${myecho}  "${app}"
done

This one returns ./script2.sh: line 7: foo: command not found, foo is the name of app. What's the difference between I use echo directly and using myecho as a aliases?

Thomas Dickey

In this command

myecho=$(echo)

you are setting myecho to an empty token. So the following command

${myecho}  "${app}"

is simply "${app}", which is apparently "foo" (not what was intended). You would make an alias using different syntax:

alias myecho="echo"

Further reading:

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

What is the difference between using params[:foo] and @foo?

From Dev

What's the difference between if ! [[ foo ]] and if [[ ! foo ]] in Bash?

From Dev

What is the difference between '$ . foo' and '$ ./foo'?

From Dev

What's the difference between `declare foo` and `foo=` in Bash?

From Dev

What's the difference between Foo::new and () -> new Foo()?

From Dev

What's the difference between `declare foo` and `foo=` in Bash?

From Dev

What is the difference between &foo::function and foo::function?

From Dev

What is the difference between ifeq( $(foo), ) and ifndef foo

From Dev

What is the difference between $foo === TRUE and TRUE === $foo

From Dev

What is the difference between `my $foo` and `my ($foo)`?

From Dev

What is the difference between ifeq( $(foo), ) and ifndef foo

From Dev

Difference between <%= foo %> and ${ foo }

From Dev

Difference between <%= foo %> and ${ foo }

From Dev

What is the difference between s"foo $bar" and "foo %s".format(bar) in scala

From Dev

What is the difference between s"foo $bar" and "foo %s".format(bar) in scala

From Dev

Difference between @foo, self.foo, and foo?

From Dev

PHP: Is there a difference between {$foo} and ${foo}

From Dev

difference between "function foo() {}" and "foo() {}"

From Dev

Typed arrays in TypeScript - what is the difference between Array<Foo> and Foo[]?

From Dev

What is the difference between foo(int arr[]) and foo(int arr[10])?

From Dev

What is the difference between Boolean(foo.bar) and !!foo.bar?

From Dev

Typed arrays in TypeScript - what is the difference between Array<Foo> and Foo[]?

From Dev

difference between calling command directly and using keybinding

From Dev

What's the difference between using quotation with parameters and not using in a shell script

From Dev

What's is the difference between ">" and ">>" in shell command?

From Dev

What's is the difference between ">" and ">>" in shell command?

From Dev

what is difference between foo=bar(foo) and something=bar(foo) in decorator in python?

From Dev

what's the difference between using 'single quotes' or not in find command

From Dev

Difference between (?=.*foo\b) and (?=.*foo)\b

Related Related

  1. 1

    What is the difference between using params[:foo] and @foo?

  2. 2

    What's the difference between if ! [[ foo ]] and if [[ ! foo ]] in Bash?

  3. 3

    What is the difference between '$ . foo' and '$ ./foo'?

  4. 4

    What's the difference between `declare foo` and `foo=` in Bash?

  5. 5

    What's the difference between Foo::new and () -> new Foo()?

  6. 6

    What's the difference between `declare foo` and `foo=` in Bash?

  7. 7

    What is the difference between &foo::function and foo::function?

  8. 8

    What is the difference between ifeq( $(foo), ) and ifndef foo

  9. 9

    What is the difference between $foo === TRUE and TRUE === $foo

  10. 10

    What is the difference between `my $foo` and `my ($foo)`?

  11. 11

    What is the difference between ifeq( $(foo), ) and ifndef foo

  12. 12

    Difference between <%= foo %> and ${ foo }

  13. 13

    Difference between <%= foo %> and ${ foo }

  14. 14

    What is the difference between s"foo $bar" and "foo %s".format(bar) in scala

  15. 15

    What is the difference between s"foo $bar" and "foo %s".format(bar) in scala

  16. 16

    Difference between @foo, self.foo, and foo?

  17. 17

    PHP: Is there a difference between {$foo} and ${foo}

  18. 18

    difference between "function foo() {}" and "foo() {}"

  19. 19

    Typed arrays in TypeScript - what is the difference between Array<Foo> and Foo[]?

  20. 20

    What is the difference between foo(int arr[]) and foo(int arr[10])?

  21. 21

    What is the difference between Boolean(foo.bar) and !!foo.bar?

  22. 22

    Typed arrays in TypeScript - what is the difference between Array<Foo> and Foo[]?

  23. 23

    difference between calling command directly and using keybinding

  24. 24

    What's the difference between using quotation with parameters and not using in a shell script

  25. 25

    What's is the difference between ">" and ">>" in shell command?

  26. 26

    What's is the difference between ">" and ">>" in shell command?

  27. 27

    what is difference between foo=bar(foo) and something=bar(foo) in decorator in python?

  28. 28

    what's the difference between using 'single quotes' or not in find command

  29. 29

    Difference between (?=.*foo\b) and (?=.*foo)\b

HotTag

Archive