Variable defined w/ blank in {} can't work

37 Views Asked by At

I have a file A.f which contain only one line of

Check something: {nameA nameB nameC}

then, I define a variable named var_A like

set var_A = `grep "Check something" A.f | head -n 1`

but this set failed with error msg of

Missing }.

It quite confuse me, so I have a test of:

echo {0}.    # 0
echo {0 1}.  # Missing }.
echo {0 }.   # Missing }.
echo "{0 1}" # {0,1}

which confuse me more, but I can find any meaning of {} in cshell is just about {} as a shorthand in list form.

Does anyone know why {} cant contain any blank?

1

There are 1 best solutions below

0
Armali On

Does anyone know why {} cant contain any blank?

See the man page section Filename substitution:

If a word contains … `{' …, then that word is a candidate for filename substitution…

Note that an unquoted word can't contain any blank. We can't expect to be able to use special characters unquoted, so let's quote them:

set var_A = "`grep Check\ something A.f | head -n 1`"