dynamically adding values in c-shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting dynamically adding values in c-shell
# 1  
Old 05-01-2010
dynamically adding values in c-shell

I am needing to create a variable(changing) and assign it a value(changing) ... I am using C-Shell..

Example:

foreach account in ($Accountlist)
set account_connect = "$account/$account_pass"
end

I want to make set account_connect to store various values ? $account_connect did not work....
# 2  
Old 05-01-2010
Hi.

Writing it does not work does not help us help you. Post the error messages(s).

You're an old hand here, so you know that it's best to use CODE tags around code and data. You'll be inviting more responses if you do that.

Here is an example that uses underscores in names with a foreach:
Code:
#!/bin/csh

# @(#) s1       Demonstrate foreach.

# Infrastructure details, environment, commands for forum posts. 
# Uncomment export / setenv command to run script as external user.
# export PATH="/usr/local/bin:/usr/bin:/bin"
# setenv PATH "/usr/local/bin:/usr/bin:/bin"
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" csh
echo

set my_list = ( the hole in the wall gang )

echo $my_list

foreach item ( $my_list )
        echo $item
end

prodiucing:
Code:
$ ./s1

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility version)
OS, ker|rel, machine: SunOS, 5.10, i86pc
csh Aug 8 2006 (SunOS 5.10)

the hole in the wall gang
the
hole
in
the
wall
gang

As you probably have seen in your searches here at unix.com, the use of csh / tcsh for scripting is discouraged for a number of reasons. If you can, use the Bourne shell family for scripting: sh, bash, ksh, zsh.

Best wishes ... cheers, drl
# 3  
Old 05-02-2010
My requirement is for C-shell and hoe people would have understood the issue clearly. it is about populating a variable with various string values during the execution.
# 4  
Old 05-02-2010
Hi Shafi
Its not clear what exactly you are trying to ask because if i had understood you correctly, the answer which you are looking for is present in the example which you provided, the set command.

However, if the set command which you have shown is throwing error, the only reason i could think of is the variable "account_pass" did not have any initial value, and hence it fails.

If this is not what you are looking for, please show us the error that you have encountered.


Thanks
Guru.

Last edited by Scott; 05-04-2010 at 08:37 AM.. Reason: Removed self-promotion link
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 dynamically name as function in shell?

Hi all, Does anyone know if it possible to append a parameter to a function name? Something like the following: function tnsrec_${SERVICE_NAME} { code.. } Any ideas? (6 Replies)
Discussion started by: jonnyd
6 Replies

2. UNIX for Dummies Questions & Answers

Dynamically merging 2 files on header values

Hi All, I have 2 files which i need to merge together based on the column names provided in the file. The first line in both files are header records. The first file has fixed columns but second file can have subset of the columns from file 1 File 1: ... (6 Replies)
Discussion started by: kushagra
6 Replies

3. UNIX for Dummies Questions & Answers

Adding column with values

Dear all, I need your help for my question please I have without header (space separated) and need to add two colomns at the beginning with values my file look like : rs1 a t 0.6 rs2 a c 0.3 rs3 t g 0.8 I need to a new file like: 1 100 rs1 a t 0.6 1 100 rs2 a c 0.3 1 100 rs3 t g... (3 Replies)
Discussion started by: biopsy
3 Replies

4. Shell Programming and Scripting

Modifying the values of dynamically named arrays

Hi all, In ksh, I'm trying to loop through all of my arrays, named array1, array2, array3..., and update the indices. But I'm getting errors and I'm not sure how to fix them. The errors are ./parse.sh: 6+1: not found The code is: eval \${array$c}=$(eval \${array$c}+1 ) Any help... (12 Replies)
Discussion started by: nicksantos1
12 Replies

5. Programming

Retreving the dynamically allocated values from bdb using C

In one of the assignment which i am working on, i am am trying to insert keys and values into BDB by reading the input records from a input file as below. Here keys i am inserting as character buffer and for values i am dynamically allocating the memory using malloc and then inserting into bdb.... (1 Reply)
Discussion started by: AmbikaValagonda
1 Replies

6. UNIX for Advanced & Expert Users

Retreving the dynamically allocated values from bdb using C

In one of the assignment which i am working on, i am am trying to insert keys and values into BDB by reading the input records from a input file as below. Here keys i am inserting as character buffer and for values i am dynamically allocating the memory using malloc and then inserting into bdb.... (1 Reply)
Discussion started by: AmbikaValagonda
1 Replies

7. Shell Programming and Scripting

Adding string variable dynamically in for loop

Hi, I need to generate the text name dynamically in for loop, ex, VAR_COPY_FILE1= file path 1 VAR_COPY_FILE2= file path 2 VAR_COPY_FILE3= file path 3 for i in 1 2 3 do if then "do some process here" fi done (3 Replies)
Discussion started by: msubash26
3 Replies

8. Shell Programming and Scripting

Adding values concatenating values

I have the following script in a shell # The start of a filename file=$(ls -tr $EMT*.dat | tail -1) # Select the latest file echo $file file_seq=$( < /u02/sct/banner/bandev2/xxxxxx/misc/EFTSQL.dat) echo $file_seq file2 = '$file_seq + 1' echo $file2 It is reading a file EFTSQL.dat... (3 Replies)
Discussion started by: rechever
3 Replies

9. Shell Programming and Scripting

Adding the values of two file

I have two files as Count1 and Count2. The count contains only one values as 10 and count2 contains only one values as 20. Now I want third file Count3 as count1+Count2. That is it should contain sum of two file(10+20=30) (3 Replies)
Discussion started by: Shell_Learner
3 Replies

10. Shell Programming and Scripting

Managing dynamically multiple shell

I want to launch some shell scripts. I would have the possibility to change the number of shell scripts launched dynamically by modifying a variable, or a configuration file. For example, I start to launch 4 scripts at the same time, and after that, by modifying a variable, 6 scripts are... (0 Replies)
Discussion started by: gonzo38
0 Replies
Login or Register to Ask a Question