Sponsored Content
Top Forums Shell Programming and Scripting Bash variable within variable Post 302927266 by yifangt on Monday 1st of December 2014 06:16:47 PM
Old 12-01-2014
Came across a more complicate scenario on top the previous post by looping two layers:
Code:
for I in 1{01..32} 20{0..9}
do 
for J in A1 A2 B1 B2
mkdir -p DES_P${I}${J}
cp SRC_P${I}${J} DES_P{I}${J}
# cp ${!SRC_P${I}${J}} ${!DES_P{I}${J}}               # Did not work:  -Bash: ${!SRC_P${I}${J}}: bad substitution
done
done

There are 168 folders. All the SRC_P${I}${J} were manually collected and defined from different folders (irregular, not even easy to do by regex) like:
Code:
SRC_P101A1=/home/apple/201310512/finished/Summary
SRC_P101A2=/home/orange/201311511/second_try/redo
etc
......

How to loop through the two layers and make the destination folders organized nicer and for easier peek-into in the future? Or am I thinking the wrong way? Thanks!

Last edited by yifangt; 12-01-2014 at 07:27 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

passing variable from bash to perl from bash script

Hi All, I need to pass a variable to perl script from bash script, where in perl i am using if condition. Here is the cmd what i am using in perl FROM_DATE="06/05/2008" TO_DATE="07/05/2008" "perl -ne ' print if ( $_ >="$FROM_DATE" && $_ <= "$TO_DATE" ) ' filename" filename has... (10 Replies)
Discussion started by: arsidh
10 Replies

2. Shell Programming and Scripting

bash and ksh: variable lost in loop in bash?

Hi, I use AIX (ksh) and Linux (bash) servers. I'm trying to do scripts to will run in both ksh and bash, and most of the time it works. But this time I don't get it in bash (I'm more familar in ksh). The goal of my script if to read a "config file" (like "ini" file), and make various report.... (2 Replies)
Discussion started by: estienne
2 Replies

3. Shell Programming and Scripting

BASH get variable according to name of another variable

Just started BASH scripting, and I tried to make a script 'args' to display all of the arguments that I give to it. #!/bin/bash if then echo "No arguments specified." fi val= for ((i=1; i <= $# ; i++)) do eval "\$val=\$$i" echo "Argument number $i is $var." done However... (3 Replies)
Discussion started by: test_test
3 Replies

4. Shell Programming and Scripting

Using the value of one variable to name another variable (in bash)

Hello all, I'm working on a script, and as part of it, I'm trying to create a loop that will run through a stored piece of information a certain number of times pulling out information, and each time create a variable with a unique name that will store that information. I'm sure it's a simple... (3 Replies)
Discussion started by: DeCoTwc
3 Replies

5. Shell Programming and Scripting

[Bash]variable does not keep its value

Hello all, I have this shell script, but do not understand why the variables inside the if block does not keep its value outside. Is it because of the pipe ? How can i fix this problem ? Thank you for helping. local alarm="" local num_alarm=0 local -a alarms ... (3 Replies)
Discussion started by: trickstar
3 Replies

6. Shell Programming and Scripting

How to define a variable with variable definition is stored in a variable?

Hi all, I have a variable say var1 (output from somewhere, which I can't change)which store something like this: echo $var1 name=fred age=25 address="123 abc" password=pass1234 how can I make the variable $name, $age, $address and $password contain the info? I mean do this in a... (1 Reply)
Discussion started by: freddy1228
1 Replies

7. Shell Programming and Scripting

bash - Variable made of variable

Hello, I am struggling with using variable made using "eval". a=4 eval b$a=20 echo $b$a ??? As shown above, I am trying to call back the variable "bX" assuming I do not know the value of "a". How can I do that? I tried several combinations but nothing worked. Thanks (10 Replies)
Discussion started by: jolecanard
10 Replies

8. Shell Programming and Scripting

Use variable in bash

$ p="1 2 5 8" $ set -- $p $ echo $3 5 $ k=3 $ echo \$${k} $3 I want the "echo \$${k}" to get the output 5 , how to modify ? (6 Replies)
Discussion started by: yanglei_fage
6 Replies

9. Shell Programming and Scripting

Variable in bash help

#aa=xxxx #zz="cc $aa" #aa=gggg #echo $zz out put is cc xxxx if I want to get cc gggg how should I do, I don't want to write zz="c $aa " after aa=gggg (2 Replies)
Discussion started by: yanglei_fage
2 Replies

10. Shell Programming and Scripting

Bash variable available for use outside loop

In the below for loop, I extract a variable $d which is an id that will change each time. The bash executes the problem that I am having is that p (after the done) is the path with the extracted $d. However, I can not use it in subsequent loops as it is not reconized. I have been trying to change... (3 Replies)
Discussion started by: cmccabe
3 Replies
set_color(1)							       fish							      set_color(1)

NAME
set_color - set_color - set the terminal color set_color - set the terminal color Synopsis set_color [-v --version] [-h --help] [-b --background COLOR] [COLOR] Description Change the foreground and/or background color of the terminal. COLOR is one of black, red, green, brown, yellow, blue, magenta, purple, cyan, white and normal. o -b, --background Set the background color o -c, --print-colors Prints a list of all valid color names o -h, --help Display help message and exit o -o, --bold Set bold or extra bright mode o -u, --underline Set underlined mode o -v, --version Display version and exit Calling set_color normal will set the terminal color to whatever is the default color of the terminal. Some terminals use the --bold escape sequence to switch to a brighter color set. On such terminals, set_color white will result in a grey font color, while set_color --bold white will result in a white font color. Not all terminal emulators support all these features. This is not a bug in set_color but a missing feature in the terminal emulator. set_color uses the terminfo database to look up how to change terminal colors on whatever terminal is in use. Some systems have old and incomplete terminfo databases, and may lack color information for terminals that support it. Download and install the latest version of ncurses and recompile fish against it in order to fix this issue. Version 1.23.1 Sun Jan 8 2012 set_color(1)
All times are GMT -4. The time now is 02:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy