![]() |
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 |
| Awk and Variables | deepak4you | Shell Programming and Scripting | 4 | 11-15-2007 09:18 AM |
| Variables | bobo | UNIX for Dummies Questions & Answers | 1 | 01-19-2007 01:37 AM |
| doing a sed on certain variables | seaten | UNIX for Dummies Questions & Answers | 10 | 09-05-2005 11:45 PM |
| doing a sed with variables | seaten | Shell Programming and Scripting | 1 | 05-06-2005 04:08 PM |
| doing a sed with variables | seaten | UNIX for Dummies Questions & Answers | 1 | 05-06-2005 03:48 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Using Variables to Set Other Variables
I have a script that I'm trying to shorten (below) by removing repetitive code.
if [[ -a ${abccontrols}/Commodity_NDM_${alt_db}_done ]] then commodity_ndm_done=Y fi if [[ -a ${abccontrols}/Customer_NDM_${alt_db}_done ]] then customer_ndm_done=Y fi if [[ -a ${abccontrols}/Department_NDM_${alt_db}_done ]] then department_ndm_done=Y fi if [[ -a ${abccontrols}/Division_NDM_${alt_db}_done ]] then division_ndm_done=Y fi if [[ -a ${abccontrols}/Order_Detail_NDM_${alt_db}_done ]] then order_detail_ndm_done=Y fi if [[ -a ${abccontrols}/Order_Summary_NDM_${alt_db}_done ]] then order_summary_ndm_done=Y fi if [[ -a ${abccontrols}/Witron_Forward_Pick_NDM_${alt_db}_done ]] then witron_forward_pick_ndm_done=Y fi And I tried using a loop as such: { echo "Commodity" echo "Customer" echo "Department" echo "Division" echo "Order_Detail" echo "Order_Summary" echo "Witron_Forward_Pick" } | while read v_type do if [[ -a ${abccontrols}/${v_type}_NDM_${alt_db}_done ]] then $(echo ${v_type} | tr '[A-Z]' '[a-z]')_ndm_done=Y fi done Naturally, it doesn't work. Can I make variables set other variables by this method or another? |
|
|||||
|
Not tested, but I think this will work....
Code:
#! /usr/bin/ksh
typeset -l var
LIST="Commodity Customer Department Division Order_Detail Order_Summary Witron_Forward_Pick"
for v_type in $LIST ; do
if [ -f ${abccontrols}/${v_type}_NDM_${alt_db}_done ] ; then
var=${v_type}_ndm_done
eval \$$var=y
fi
done
exit 0
|
|
||||
|
Thanks
Thanks, guys.
Perderabo, your code worked when I removed the \$ from the eval command. But it's pretty much what I was looking for. #! /usr/bin/ksh typeset -l var for v_type in Commodity Customer Department Division Order_Detail Order_Summary Witron_Forward_Pick do if [[ -a ${abccontrols}/${v_type}_NDM__done ]]done echo "Job completion status is:" echo "Commodity_NDM = ${commodity_ndm_done}" echo "Customer_NDM = ${customer_ndm_done}" echo "Department_NDM = ${department_ndm_done}" echo "Division_NDM = ${division_ndm_done}" echo "Order_Detail_NDM = ${order_detail_ndm_done}" echo "Order_Summary_NDM = ${order_summary_ndm_done}" echo "Witron_Forward_Pick_NDM = ${witron_forward_pick_ndm_done}\n" and the output is correct (the last file being missing) Job completion status is: Commodity_NDM = Y Customer_NDM = Y Department_NDM = Y Division_NDM = Y Order_Detail_NDM = Y Order_Summary_NDM = Y Witron_Forward_Pick_NDM = N |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|