lassign(n) Tcl Built-In Commands lassign(n)
__________________________________________________________________________________________________________________________________________________NAME
lassign - Assign list elements to variables
SYNOPSIS
lassign list varName ?varName ...?
_________________________________________________________________DESCRIPTION
This command treats the value list as a list and assigns successive elements from that list to the variables given by the varName arguments
in order. If there are more variable names than list elements, the remaining variables are set to the empty string. If there are more
list elements than variables, a list of unassigned elements is returned.
EXAMPLES
An illustration of how multiple assignment works, and what happens when there are either too few or too many elements.
lassign {a b c} x y z ;# Empty return
puts $x ;# Prints "a"
puts $y ;# Prints "b"
puts $z ;# Prints "c"
lassign {d e} x y z ;# Empty return
puts $x ;# Prints "d"
puts $y ;# Prints "e"
puts $z ;# Prints ""
lassign {f g h i} x y ;# Returns "h i"
puts $x ;# Prints "f"
puts $y ;# Prints "g"
The lassign command has other uses. It can be used to create the analogue of the "shift" command in many shell languages like this:
set ::argv [lassign $::argv argumentToReadOff]
SEE ALSO
lindex(n), list(n), lset(n), set(n)
KEYWORDS
assign, element, list, multiple, set, variable
Tcl 8.5 lassign(n)
Check Out this Related Man Page
lassign(n) Tcl Built-In Commands lassign(n)
__________________________________________________________________________________________________________________________________________________NAME
lassign - Assign list elements to variables
SYNOPSIS
lassign list varName ?varName ...?
_________________________________________________________________DESCRIPTION
This command treats the value list as a list and assigns successive elements from that list to the variables given by the varName arguments
in order. If there are more variable names than list elements, the remaining variables are set to the empty string. If there are more
list elements than variables, a list of unassigned elements is returned.
EXAMPLES
An illustration of how multiple assignment works, and what happens when there are either too few or too many elements.
lassign {a b c} x y z ;# Empty return
puts $x ;# Prints "a"
puts $y ;# Prints "b"
puts $z ;# Prints "c"
lassign {d e} x y z ;# Empty return
puts $x ;# Prints "d"
puts $y ;# Prints "e"
puts $z ;# Prints ""
lassign {f g h i} x y ;# Returns "h i"
puts $x ;# Prints "f"
puts $y ;# Prints "g"
The lassign command has other uses. It can be used to create the analogue of the "shift" command in many shell languages like this:
set ::argv [lassign $::argv argumentToReadOff]
SEE ALSO
lindex(n), list(n), lset(n), set(n)
KEYWORDS
assign, element, list, multiple, set, variable
Tcl 8.5 lassign(n)
Is it possible to process multiple variables in a single sed command?
I have the following ksh with three variables and I want to search for all variables which start with "var" inside input.txt.
I tired "$var$" but it just prints out everyting in input.txt and does not work.
$ more test.ksh... (5 Replies)
one of my colleagues has this question.
he has a command, C_CMD which accepts 4 variables, $1 $2 $3 $4
he wants to load up a file with multiple rows, one row per set of variables and then iteratively execute the command based on the content of the file.
example:
at the command line you'd... (5 Replies)
i want to assign a anme for a string, i got the things below, but it doesn't work.
MParc1=``
if
then
$MPrac1=`Prac1` # assign $MPrac1 to Prac1
else
$MPrac1=`` #assigne $MPrac1 to nothing
fi
echo "${MPrac1} >>file
Output: (if num is 0)
Prac1
can you please... (6 Replies)
Guys anyone know how i can store fields into multiple variables in one go?
I'm wanting to grab the disk id's from format into disk1 and disk2
Below is what i want to work but i know it doesnt :-
: | format | awk '/^(\ +)/ {print $2}' | read disk1 disk2
The below does work...but i don't... (5 Replies)
Hi all,
I'm trying to do something that might be basic, but it is not working for me, and I suspect I'm missing something.
I appreciate if you can shed a light or offer an alternative.
In expect script, I'm opening a file i.e:
set file I have a simple proc:
proc a {} { puts "Hello... (3 Replies)
Hi Folks,
I am trying to assign a value from the command to a dynamic variable. But I am not getting the desired output.. I am sure something is wrong so i need experts advise.
There will be multiple files like /var/tmp/server_1, /var/tmp/server_2, /var/tmp/server_3, having different server... (6 Replies)
Hello everyone,
What is the difference between these two tcl commands:
(A) --> puts "ERROR!!! ${current_name}/${opt} is not found."
(B) --> puts "ERROR!!! $current_name/$opt is not found."
Are the braces needed to be put? Or both A and B has the same output? (5 Replies)
Hi All,
here D Prints the bytes value .plz help to convert the variable D value to MB in new variable $E
D=`more $C |awk '{print $6;}'`
Thanks in Advance.:) (3 Replies)
Experts,
I want to set value of variables like this in bash shell:
i=5 ; L=100
I want variable d5 (that is d(i) ) to be assign the value of $L ,
d$i=$L ; echo $d5
Not working
Thanks., (3 Replies)
Hi, I have a variable which read the value from the lines, and if it is empty string (5 bytes), then I have to assign this variable to zero "0", it able to detect the data is empty by showing me the message "empty", but not able to assign it as zero.
WTHP=`echo "$file" | cut -c158-162`
if ]... (5 Replies)
I am trying to write a simple function to select values from a database and assign them to variables. It can have any number of arguments sent into it, and I want to assign the value retrieved to a different variable name for each argument sent in. So my code looks something like this:
... (6 Replies)
I have a file containing multiple values, some of them are pipe separated which are to be read as separate values and some of them are single value all are these need to store in variables.
I need to read this file which is an input to my script
Config.txt
file name, first path, second... (7 Replies)
How does one assign a variable, x to equal the number of records in a different file.
I have a simple command such as below:
awk -F "\t" '(NR>5) { if(($x == "0/0")) { print $0} }' a.txt > a1.txt
but I want x to equal the number of records in a different file, b.txt (10 Replies)
Hi folks,
I have a list of variables as follows:
CDBTEST1
messdba1
sat11cru1
s12tgts1
sa12ss1
I need to remove the last '1' so I can use the remaining variables in a for loop:
CDBTEST
messdba
sat11cru
s12tgts
sa12ss
Something like this: (3 Replies)
Hi Guys,
I need to assign the value of which has rows to a variable, Can you advise how to do that
hive --orcfiledump /hdfs_path/ | grep "Rows"
Rows: 131554
I need to assign this row count itself to a unix variable
count=$(hive --orcfiledump /hdfs_path/ | grep "Rows")
Expected ... (6 Replies)