Skip to main content
added 367 characters in body
Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k
if ($mystr:q =~ *'\
'*) echo yes

should work in some implementations and versions of csh (like the csh and tcsh ones found on Debian). In some others (like the one found on Solaris 10), you may have better luck with

set nl = '\
'
if ($mystr:q =~ *$nl:q*) echo yes

Most people have given up trying to write reliable scripts with csh by now. Why would you use csh in this century?

This code works for me (outputs no) in tcsh 6.17.00 (Astron) 2009-07-10 (x86_64-unknown-linux) options wide,nls,dl,al,kan,rh,color,filec

set mystr = '1234ABC\
 -------\
FOOBAR'
if ($mystr:q !~ *'\
'*) then
  echo yes
else
  echo no
endif

Note that if you do:

set var = `some command`

csh stores each word (blank separated) of the output of some command in several elements of the var array.

With:

set var = "`some command`"

it stores each non-empty line in elements of the array.

It looks like one cannot1 store the output of a command whole into a variable in (t)csh, so your only option would be:

set var = "`some command`" # note that it removes the empty lines
if ($#var == 1)...

1 Strictly speaking, that's not true, one could do something like:

set x = "`some command | paste -d. /dev/null -`"
set var = ""
set nl = '\
'

foreach i ($x:q)
  set i = $i:s/.//:q
  set var = $var:q$i:q$nl:q
end

(of course, it may not work in all csh implementations/versions)

if ($mystr:q =~ *'\
'*) echo yes

should work in some implementations and versions of csh (like the csh and tcsh ones found on Debian). In some others (like the one found on Solaris 10), you may have better luck with

set nl = '\
'
if ($mystr:q =~ *$nl:q*) echo yes

Most people have given up trying to write reliable scripts with csh by now. Why would you use csh in this century?

This code works for me (outputs no) in tcsh 6.17.00 (Astron) 2009-07-10 (x86_64-unknown-linux) options wide,nls,dl,al,kan,rh,color,filec

set mystr = '1234ABC\
 -------\
FOOBAR'
if ($mystr:q !~ *'\
'*) then
  echo yes
else
  echo no
endif

Note that if you do:

set var = `some command`

csh stores each word (blank separated) of the output of some command in several elements of the var array.

With:

set var = "`some command`"

it stores each non-empty line in elements of the array.

It looks like one cannot store the output of a command whole into a variable in (t)csh, so your only option would be:

set var = "`some command`" # note that it removes the empty lines
if ($#var == 1)...
if ($mystr:q =~ *'\
'*) echo yes

should work in some implementations and versions of csh (like the csh and tcsh ones found on Debian). In some others (like the one found on Solaris 10), you may have better luck with

set nl = '\
'
if ($mystr:q =~ *$nl:q*) echo yes

Most people have given up trying to write reliable scripts with csh by now. Why would you use csh in this century?

This code works for me (outputs no) in tcsh 6.17.00 (Astron) 2009-07-10 (x86_64-unknown-linux) options wide,nls,dl,al,kan,rh,color,filec

set mystr = '1234ABC\
 -------\
FOOBAR'
if ($mystr:q !~ *'\
'*) then
  echo yes
else
  echo no
endif

Note that if you do:

set var = `some command`

csh stores each word (blank separated) of the output of some command in several elements of the var array.

With:

set var = "`some command`"

it stores each non-empty line in elements of the array.

It looks like one cannot1 store the output of a command whole into a variable in (t)csh, so your only option would be:

set var = "`some command`" # note that it removes the empty lines
if ($#var == 1)...

1 Strictly speaking, that's not true, one could do something like:

set x = "`some command | paste -d. /dev/null -`"
set var = ""
set nl = '\
'

foreach i ($x:q)
  set i = $i:s/.//:q
  set var = $var:q$i:q$nl:q
end

(of course, it may not work in all csh implementations/versions)

deleted 346 characters in body
Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k
if ($mystr:q =~ *'\
'*) echo yes

should work in some implementations and versions of csh (like the csh and tcsh ones found on Debian). In some others (like the one found on Solaris 10), you may have better luck with

set nl = '\
'
if ($mystr:q =~ *$nl:q*) echo yes

Most people have given up trying to write reliable scripts with csh by now. Why would you use csh in this century?

This code works for me (outputs no) in tcsh 6.17.00 (Astron) 2009-07-10 (x86_64-unknown-linux) options wide,nls,dl,al,kan,rh,color,filec

set mystr = '1234ABC\
 -------\
FOOBAR'
if ($mystr:q !~ *'\
'*) then
  echo yes
else
  echo no
endif

Note that if you do:

set var = `some command`

csh stores each word (blank separated) of the output of some command in several elements of the var array.

With:

set var = "`some command`"

it stores each non-empty line in elements of the array.

It looks like one cannot store the output of a command whole into a variable in (t)csh, so your only option would be:

set var = "`some command`" # note that it removes the empty lines
if ($#var == 1)...
 
set myvar = "`some command`"

To store the output of some command into a scalar variable (or the first element of the myvar array if you prefer) without splitting.

Alternatively you could do:

set var = `some command`
if ($#var == 1)...

(not strictly equivalent though as it wouldn't detect leading newline characters

if ($mystr:q =~ *'\
'*) echo yes

should work in some implementations and versions of csh (like the csh and tcsh ones found on Debian). In some others (like the one found on Solaris 10), you may have better luck with

set nl = '\
'
if ($mystr:q =~ *$nl:q*) echo yes

Most people have given up trying to write reliable scripts with csh by now. Why would you use csh in this century?

This code works for me (outputs no) in tcsh 6.17.00 (Astron) 2009-07-10 (x86_64-unknown-linux) options wide,nls,dl,al,kan,rh,color,filec

set mystr = '1234ABC\
 -------\
FOOBAR'
if ($mystr:q !~ *'\
'*) then
  echo yes
else
  echo no
endif

Note that if you do:

set var = `some command`

csh stores each word (blank separated) of the output of some command in several elements of the var array.

With:

set var = "`some command`"

it stores each non-empty line in elements of the array.

It looks like one cannot store the output of a command whole into a variable in (t)csh, so your only option would be:

set var = "`some command`" # note that it removes the empty lines
if ($#var == 1)...
 
set myvar = "`some command`"

To store the output of some command into a scalar variable (or the first element of the myvar array if you prefer) without splitting.

Alternatively you could do:

set var = `some command`
if ($#var == 1)...

(not strictly equivalent though as it wouldn't detect leading newline characters

if ($mystr:q =~ *'\
'*) echo yes

should work in some implementations and versions of csh (like the csh and tcsh ones found on Debian). In some others (like the one found on Solaris 10), you may have better luck with

set nl = '\
'
if ($mystr:q =~ *$nl:q*) echo yes

Most people have given up trying to write reliable scripts with csh by now. Why would you use csh in this century?

This code works for me (outputs no) in tcsh 6.17.00 (Astron) 2009-07-10 (x86_64-unknown-linux) options wide,nls,dl,al,kan,rh,color,filec

set mystr = '1234ABC\
 -------\
FOOBAR'
if ($mystr:q !~ *'\
'*) then
  echo yes
else
  echo no
endif

Note that if you do:

set var = `some command`

csh stores each word (blank separated) of the output of some command in several elements of the var array.

With:

set var = "`some command`"

it stores each non-empty line in elements of the array.

It looks like one cannot store the output of a command whole into a variable in (t)csh, so your only option would be:

set var = "`some command`" # note that it removes the empty lines
if ($#var == 1)...
Post Undeleted by Stéphane Chazelas
added 292 characters in body
Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k
if ($mystr:q =~ *'\
'*) echo yes

should work in some implementations and versions of csh (like the csh and tcsh ones found on Debian). In some others (like the one found on Solaris 10), you may have better luck with

set nl = '\
'
if ($mystr:q =~ *$nl:q*) echo yes

Most people have given up trying to write reliable scripts with csh by now. Why would you use csh in this century?

This code works for me (outputs no) in tcsh 6.17.00 (Astron) 2009-07-10 (x86_64-unknown-linux) options wide,nls,dl,al,kan,rh,color,filec

set mystr = '1234ABC\
 -------\
FOOBAR'
if ($mystr:q !~ *'\
'*) then
  echo yes
else
  echo no
endif

Note that if you do:

set var = `some command`

Andcsh stores each word (blank separated) of the output of some command outputsin several lines, then csh will split that and storeelements of the var array.

With:

set var = "`some command`"

it stores each non-empty line into separatein elements of the array. You need

It looks like one cannot store the output of a command whole into a variable in (t)csh, so your only option would be:

set var = "`some command`" # note that it removes the empty lines
if ($#var == 1)...

set myvar = "`some command`"

To store the output of some command into a scalar variable (or the first element of the myvar array if you prefer) without splitting.

Alternatively you could do:

set var = `some command`
if ($#var == 1)...

(not strictly equivalent though as it wouldn't detect leading newline characters

if ($mystr:q =~ *'\
'*) echo yes

should work in some implementations and versions of csh (like the csh and tcsh ones found on Debian). In some others (like the one found on Solaris 10), you may have better luck with

set nl = '\
'
if ($mystr:q =~ *$nl:q*) echo yes

Most people have given up trying to write reliable scripts with csh by now. Why would you use csh in this century?

This code works for me (outputs no) in tcsh 6.17.00 (Astron) 2009-07-10 (x86_64-unknown-linux) options wide,nls,dl,al,kan,rh,color,filec

set mystr = '1234ABC\
 -------\
FOOBAR'
if ($mystr:q !~ *'\
'*) then
  echo yes
else
  echo no
endif

Note that if you do:

set var = `some command`

And some command outputs several lines, then csh will split that and store each non-empty line into separate elements of the array. You need:

set myvar = "`some command`"

To store the output of some command into a scalar variable (or the first element of the myvar array if you prefer) without splitting.

Alternatively you could do:

set var = `some command`
if ($#var == 1)...

(not strictly equivalent though as it wouldn't detect leading newline characters

if ($mystr:q =~ *'\
'*) echo yes

should work in some implementations and versions of csh (like the csh and tcsh ones found on Debian). In some others (like the one found on Solaris 10), you may have better luck with

set nl = '\
'
if ($mystr:q =~ *$nl:q*) echo yes

Most people have given up trying to write reliable scripts with csh by now. Why would you use csh in this century?

This code works for me (outputs no) in tcsh 6.17.00 (Astron) 2009-07-10 (x86_64-unknown-linux) options wide,nls,dl,al,kan,rh,color,filec

set mystr = '1234ABC\
 -------\
FOOBAR'
if ($mystr:q !~ *'\
'*) then
  echo yes
else
  echo no
endif

Note that if you do:

set var = `some command`

csh stores each word (blank separated) of the output of some command in several elements of the var array.

With:

set var = "`some command`"

it stores each non-empty line in elements of the array.

It looks like one cannot store the output of a command whole into a variable in (t)csh, so your only option would be:

set var = "`some command`" # note that it removes the empty lines
if ($#var == 1)...

set myvar = "`some command`"

To store the output of some command into a scalar variable (or the first element of the myvar array if you prefer) without splitting.

Alternatively you could do:

set var = `some command`
if ($#var == 1)...

(not strictly equivalent though as it wouldn't detect leading newline characters

Post Deleted by Stéphane Chazelas
added 292 characters in body
Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k
Loading
added 292 characters in body
Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k
Loading
added 292 characters in body
Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k
Loading
added 241 characters in body
Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k
Loading
deleted 171 characters in body
Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k
Loading
Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k
Loading