Sponsored Content
Full Discussion: Dynamic variable assignment
Top Forums Shell Programming and Scripting Dynamic variable assignment Post 302973964 by Corona688 on Tuesday 24th of May 2016 01:14:54 PM
Old 05-24-2016
Oh. That's the exact opposite of dynamic, when you know the variable names you want already.
Code:
exec 5<file.csv # Open file into FD 5

# Read first line
IFS="," read VAR1 VAR2 VAR3 VAR4 <&5
# Read second line
IFS="," read VAR1 VAR2 VAR3 VAR4 <&5
# etc

# A loop 
while IFS="," read VAR1 VAR2 VAR3 VAR4 <&5
do
        echo "column 1 is $VAR1"
done

# close file
exec 5<&-

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

@ in a variable assignment

Hello Everybody, Does anyone know what the @ symbol means in a csh script, if used with a variable assignment as below @ line = 1 why not just use.... set line=1 Many thanks rkap (1 Reply)
Discussion started by: rkap
1 Replies

2. Shell Programming and Scripting

Dynamic variable assignment

Hi All, I have the below scenario: A file test.cfg with three fields>> DATA1 DATA2 DATA3 In the script I need to assign each of the fields to variables. The number of fields will not be constant (this case we have three). Im trying to do something like this: NUM=1 OUT_DAT_NO=3 ... (4 Replies)
Discussion started by: deepakgang
4 Replies

3. Shell Programming and Scripting

variable assignment using awk

Guys, Could you please help me out. I need two values in two variables using awk from the o/p of grep. example:- grep sdosanjh <filename> sdosanjh myhostname myfilename NOW WHAT I WANT IS :- sdosanjh should be in variable (say NAME) myhostname should be in variable (say... (8 Replies)
Discussion started by: sdosanjh
8 Replies

4. Shell Programming and Scripting

eval and variable assignment

Hi, i have an issue with eval and variable assignment. 1) i have a date value in a variable and that date is part of a filename, var1=20100331 file1=${var1}-D1-0092.xml.zip file2=${var2}-D2-0092.xml.zip file3=${var3}-D3-0092.xml.zip i am passing the above variables to a script via... (11 Replies)
Discussion started by: mohanpadamata
11 Replies

5. Shell Programming and Scripting

Dynamic variable assignment

Hi all, I’m very new to UNIX programming. I have a question on dynamic variable 1. I’m having delimited file (only one row). First of all, I want to count number of columns based on delimiter. Then I want to create number of variables equal to number of fields. Say number of... (5 Replies)
Discussion started by: mkarthykeyan
5 Replies

6. Shell Programming and Scripting

Help with variable assignment

Hi, In AIX I have a variable with , (coma) separated values assigned to it like shown below var1=apple,boy,chris i want to convert this to var1='apple','boy','chris' the number of values assigned to var1 might change and it could be from 1 to n any suggestions please? (3 Replies)
Discussion started by: rahul9909
3 Replies

7. Shell Programming and Scripting

'eval' used in variable assignment

pattern1=book { x=1 eval echo \$pattern$x } book (this is the output) But when I assign a variable to the output of the eval it doesn't work unless I prefix 2 times backslash before $ as shown below. { a=`eval echo \\$pattern$x` echo $a } book Why here twice "\" has to be... (3 Replies)
Discussion started by: ravisingh
3 Replies

8. Shell Programming and Scripting

Dynamic variable assignment

My Code : -------------------------------------------- #!/bin/bash for i in `echo server1 server2` do eval ${i}_name = "apache" echo ${i}_name done -------------------------------------------- Current output : >./test.sh ./test.sh: line 5: server1_name: command not found... (3 Replies)
Discussion started by: sameermohite
3 Replies

9. Shell Programming and Scripting

Same Variable Assignment

Hi I have a strange problem: In my shell script I am performing a copy task: . prop.txt cp -r $dir/ $dir/archive $dir is fetched from a property file (prop.txt) which stores its value dir=/opt/data Now the problem is another dir1 comes into picture. I only want to add... (1 Reply)
Discussion started by: ankur328
1 Replies

10. Shell Programming and Scripting

Variable Assignment

Hi I am facing a problem. export local_folder=/opt/app/ cd /opt/app/abc/ abcversion="abc*" (abcga5 is inside /opt/app/abc/) echo $abcversion (it echoes the correct version as abcga5 ) Now when I reuse the value of abcversion for a below path: export... (6 Replies)
Discussion started by: ankur328
6 Replies
parse_dynamic_clustertoc(1M)				  System Administration Commands			      parse_dynamic_clustertoc(1M)

NAME
parse_dynamic_clustertoc - parse clustertoc file based on dynamic entries SYNOPSIS
cdrom/export/exec/sparc.Solaris_2.x/sbin/install.d/parse_dynamic_clustertoc cdrom/export/exec/i386.Solaris_2.x/sbin/install.d/parse_dynamic_clustertoc DESCRIPTION
This script parses the clustertoc file before the suninstall(1M) process is run. parse_dynamic_clustertoc is called by a modified syscon- fig script on the install CD. When parse_dynamic_clustertoc runs, it reads the clustertoc and when it encounters SUNW_CSRMBRIFF lines, it either checks the platform using the script's builtin function, or calls an external script. The script exits with a 0 if the cluster entry is included, otherwise it will be ignored. If the cluster entry is to be included, the SUNW_CSRMBRIFF =(test test_arg)cluster line is converted to SUNW_CSRMEMBER =cluster. EXAMPLES
Example 1: Checking For an SX Framebuffer The following is an example of a simple external test to check for an SX Framebuffer. The entry in the clustertoc file is shown and fol- lowing that is the script that must be placed in the install.d/dynamic_test directory. SUNW_CSRMBRIFF=(smcc.dctoc sx)SUNWCsx #! /bin/sh # # Likewise, this file is expected to live under $(TESTDIR). # case "$1" in sx) prtconf -p | grep 'SUNW,sx' 1> /dev/null;; esac FILES
cdrom/Solaris_2.x/locale/C/.clustertoc.dynamic Dynamic version of the clustertoc file cdrom/export/exec/sparc.Solaris_2.x/sbin/install.d/dynamic_test Directory that contains any additional tests cdrom/export/exec/i386.Solaris_2.x/sbin/install.d/dynamic_test Directory that contains any additional tests ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SHWPcdrom (Solaris CD) | +-----------------------------+-----------------------------+ SEE ALSO
suninstall(1M), clustertoc(4), attributes(5) SunOS 5.10 6 Sep 1995 parse_dynamic_clustertoc(1M)
All times are GMT -4. The time now is 10:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy