help with multiline variable in csh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help with multiline variable in csh
# 8  
Old 05-17-2010
Hi.
The additional code in the final while loop seems to work when the empty lines are substituted earlier with an arbitrary (but known) character, for example, #, see the sed line:
Code:
#!/usr/bin/env tcsh

# @(#) s2	Demonstrate lines into multiple-value variable, csh

echo
setenv LC_ALL C ; setenv LANG C
echo "Environment: LC_ALL = $LC_ALL, LANG = $LANG"
echo "(Versions displayed with local utility version)"
sh -c "version >/dev/null 2>&1" && version "=o" tcsh

cat > data1 <<EOF
a b c
e

f
EOF

sed -i 's/^$/#/' data1

set x = `cat data1`
echo
echo " x is |$x|"

set x = "`cat data1`"
echo
echo " x is |$x|"

set y = ( "`cat data1`" )
echo
echo " y[1] is |$y[1]|"
echo " y[2] is |$y[2]|"
echo " y[3] is |$y[3]|"
echo " y is |$y[*]|"

echo
foreach item ( $y )
echo " item is $item"
end

echo
@ i = 1
while ( $i <= ${#y} )
echo " item $i is |$y[$i]|, before test and change."
if ( "$y[$i]" =~ "#*" ) set y[$i] = ""
echo " item $i is |$y[$i]|, after  test and change."
@ i++
end
echo " The || symbols may be removed, they are there for emphasis."

exit 0

producing:
Code:
% ./s2

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility version)
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0 
tcsh 6.14.00

 x is |a b c e # f|

 x is |a b c e # f|

 y[1] is |a b c|
 y[2] is |e|
 y[3] is |#|
 y is |a b c e # f|

 item is a
 item is b
 item is c
 item is e
 item is #
 item is f

 item 1 is |a b c|, before test and change.
 item 1 is |a b c|, after  test and change.
 item 2 is |e|, before test and change.
 item 2 is |e|, after  test and change.
 item 3 is |#|, before test and change.
 item 3 is ||, after  test and change.
 item 4 is |f|, before test and change.
 item 4 is |f|, after  test and change.
 The || symbols may be removed, they are there for emphasis.

See man tcsh for details ... cheers, drl

Reminder:
Quote:
However, as noted frequently in forums, you would be better off using Bourne family shells for scripting.
# 9  
Old 05-18-2010
Hi drl

Thank you for your reply.

I have abstracted my problem by using the txt file as input source. In fact, it might be output of other commands.
For example

Code:
 
set x = ( "`isql -Uu -Pp -Ss`" )

So, I can't change contents of the input.

Anyway , I felt the limit of CSH and will try perl to solve my problem.

Thank you for your patience and time.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to set variable permanent in csh?

We are using csh on our AIX platform, if we have to export/set a specific environment variable we use setenv command but its only valid till session. How do we set that variable permanent in our csh AIX? Do we put it in userprofile file or something else? (1 Reply)
Discussion started by: aixusrsys
1 Replies

2. Shell Programming and Scripting

Assign the result of a multiline command to a variable

Hi, I have the following command that lists all the .o files from all the directories except of vwin (which I don't want it) for i in `ls -d */*.o|awk '$0 !~ "vwin"'`; do echo $i; done The result is something like that dir1/file1.o dir1/file2.o dir2/file3.o etc. So, I want to create a... (9 Replies)
Discussion started by: scor6800
9 Replies

3. Shell Programming and Scripting

Csh variable calling problem

First post on here. So I use csh shells for my research (physics... not a CS person). I am trying to rerun the same scripts, but there are ~10 files that have similar variables that I have to change for each different configuration, so I would like one central file for the variables I change that... (3 Replies)
Discussion started by: sabrepride
3 Replies

4. Shell Programming and Scripting

{bash scripting} Multiline initialisation of string variable

Hello, The task is quite simple. I need to initialise а string variable and assign to it a very long value. For the reason of readability I want to devide this long value into equal parts and place each part at a separate line. For instance, I have - ... (1 Reply)
Discussion started by: Pretoria
1 Replies

5. Shell Programming and Scripting

csh and variable values with spaces

my working shell is csh and even though if I try to run my script in plain sh, it behaves the same way. Here's a simple script: #!/bin/sh desc='"test my changes"' cmd="echo \"$desc\"" $cmd I want $desc to be passed as an argument to another command, but csh apparently doesn't like spaces in... (5 Replies)
Discussion started by: iskatel
5 Replies

6. Shell Programming and Scripting

Reading a variable in csh

I have a simple script that sets a value and reads the value in csh: set -x set a = 10 echo $a The output of the script does not show the value of a + set a = 10 + echo any help would be great. (4 Replies)
Discussion started by: pt14
4 Replies

7. UNIX for Dummies Questions & Answers

address variable content with csh

By using a csh, I want to address a variable content whose name is/matches the content of a given other variable. i.e. set name=´sam´ set ${name}_age=´27´ So, by typing: echo ${name}_age I correctly obtain: sam_age By typing: echo $sam_age or echo ${sam_age} I correctly obtain: 27 ... (1 Reply)
Discussion started by: sobolev
1 Replies

8. Shell Programming and Scripting

declare number variable in csh

Hi frind, i="1" while do echo "i is $i" data_file=$HYP_ROOT/import/efcextr$i.txt echo "$data_file" i=`expr $i + 1` done This is woring finly in ksh but not in ksh. in ksh it showing error i=1: Command not found i: Undefined variable Kindly help me ...why it is showing the error... (1 Reply)
Discussion started by: deep_kol
1 Replies

9. Shell Programming and Scripting

Pass csh variable to Perl

Hi All, I am trying to put the csh variable into a perl. In the below case, i am trying to put the csh variable "var" into my perl code. I tried to use '"$var"' but i don;t think it works. Can anybody help me pls? #!/bin/csh set var = `echo "xxx"` perl myperlcode.pl file ... (9 Replies)
Discussion started by: Raynon
9 Replies

10. Shell Programming and Scripting

csh fails when setting variable

I have a csh that is called from autosys. It fails when it hits this code env | grep Rep if ( $status == 0 ) then echo "" else setenv REP "" endif However if I run it from the command line, as opposed to from autosys (job schduler) it runs fine. I thought it might be some kind of... (2 Replies)
Discussion started by: gillbates
2 Replies
Login or Register to Ask a Question