Jump to content

Command execution

From Squishu Wiki
Revision as of 19:20, 23 August 2025 by Princesssquishuskush (talk | contribs) (Created page with "== General == * capture the result of a command's execution for use in the script * execute a command and put the output of the command into a variable * The current syntax for this ** $(command) * The older syntax for this ** `command` * the result of the $(command) is just the output from the command ** This is the string output, not the return status == Examples == * echo The current directory is $PWD ** Since PWD is a shell ENV, you don't need the special syntax * e...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

General

  • capture the result of a command's execution for use in the script
  • execute a command and put the output of the command into a variable
  • The current syntax for this
    • $(command)
  • The older syntax for this
    • `command`
  • the result of the $(command) is just the output from the command
    • This is the string output, not the return status

Examples

  • echo The current directory is $PWD
    • Since PWD is a shell ENV, you don't need the special syntax
  • echo The current users are $(who)


Assign to a variable

  • blah=$(who)
  • echo $blah