0

I have written a script that uses the below to display the amount of characters in "$var1"

echo -n "$var1" | wc -c

This displays the numeric value without an issue. However rather than display the value I wish to assign it to a the variable $char in order to then apply various conditions.

char=$(-n "$var1" | wc -c)
echo $char

However this produces the following error.

-n: command not found

RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
  • `$( -n ....)` tries to invoke a command named `-n`, and you don't have such a command. Note that everything between `$(` and the corresponding `)` is run as a command in a child process. – user1934428 Sep 28 '20 at 11:46
  • For getting the numbe of characters in `var1`, do a `echo ${#var1}`. No need to involve a child process here. – user1934428 Sep 28 '20 at 11:48
  • one step further: `char=${#var1}`, so need to invoke a sub/child process – markp-fuso Sep 28 '20 at 12:40

0 Answers0