Search code examples
bashvariablesredhat

'>' symbol whenever I try to copy results of a command to a variable


Whenever I try to save the command output to a variable terminal is stuck with a '>' symbol. I tried:

n=$(awk 'END{print NR}' 1.log')

and also

n="$(awk 'END{print NR}' 1.log')"

Every time I have to break the execution using ctrl+c

what am I doing wrong here?


Solution

  • Maybe a simple typo with a stray '.

    Try this:

    n=$(awk 'END{print NR}' 1.log)
    

    The > is a prompt and an indication that bash is waiting for you to close the (stray) ' with a matching '. The exact value printed is held in the PS2 variable. The following is from the bash manual:

    PS2 The value of this parameter is expanded as with PS1 and used as the secondary prompt string. The default is '> '.