![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to make a line BLINKING in output and also how to increase font size in output | mail2sant | Shell Programming and Scripting | 3 | 04-14-2008 07:30 AM |
| Regarding PS1,PS2,PS3,PS4 variables. | anchal_khare | Shell Programming and Scripting | 5 | 02-04-2008 04:29 AM |
| assigning variables from standard output | whamchaxed | UNIX for Dummies Questions & Answers | 2 | 12-04-2007 07:31 PM |
| Assigning nawk output to variables | steveje0711 | Shell Programming and Scripting | 6 | 08-19-2005 05:03 PM |
| variables use upper case? sed : output to the same file? | gusla | UNIX for Dummies Questions & Answers | 1 | 04-05-2002 12:24 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
output ls in variables
Hi all,
I need some help for a command in a script with bash. I need the output from ls in separate variables to compare them later with other files. Example: ls map1 gives: a.txt photo.bmp log.out gcd.sh I would like to have that: a1=a.txt a2=photo.bmp ... Thanks for the help for this noob ![]() |
|
||||
|
This is not at all straightforward. Could you explain more about a scenario where this could be useful? If your shell has an array variable type (bash and ksh do), perhaps you could use that (at the cost of losing classic Bourne compatibility).
Here's a stab at implementing it. Code:
# Use plain old wildcard instead of ls, works for file names with spaces etc set -- * # files are now in $1 $2 $3 etc i=1 while true; do # Break when no arguments remain case $# in 0) break;; esac eval a$i=\$$i i=`expr $i + 1` done Note the use of eval to get a variable name with a numeric index. Last edited by era; 04-20-2008 at 08:23 AM.. Reason: Stab at implementing this |
![]() |
| Bookmarks |
| Tags |
| bash, bash eval, eval |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|