Assigning values to reference variables for a dynamic menu driven script.
How do I assign values to reference variables?
I am assigning a variable name to --> $user_var
Then I am trying to change its underlying variable value by
Code:
$((user_var))=$user_value
.. its failing,,
Please let me know if there is a way to do this dynamically..
FileA.props -->
Code:
myvar1=test1 # Variable Names and values can be changed.
myvar2=test2
myvar3=test3
# EOF
testscript.sh -->
Code:
#!/usr/bin/ksh
# Helps to change values using this menu driven script
cvsprops=FileA.props
# Executing include file, to simulate variable declaration.
# This is a must,, since its a parameter driven script.
. FileA.props
user_prompt='To Change Above Defaults Make A Selection:[n] '
PS3="${user_prompt}"
REDISPLAY=true # Helps to exit from Menu.
while [ "$REDISPLAY" == "true" ]; do
select line in $(egrep -v "#" $cvsprops ) REVIEW DONE
do
[ "$line" == "DONE" ] && REDISPLAY=false && break
[ "$line" == "REVIEW" ] && break
[ ! -n "$line" ] && echo " Invalid choice:[$REPLY]. Please make correct choice." && continue
user_var="$(echo $line | cut -d= -f1)"
user_value="$(echo $line | cut -d= -f2)"
#echo "Length of $user_value --> ${#user_value}"
# if required variable is not set. Prompt user to set it.
if [ ! -n "$user_value" ]; then
echo "Set --> ${user_var} ?: \c"
else
echo "Change --> ${user_var}:[${user_value}] ?: \c"
fi
read user_value
if [ -n $user_value ]; then
echo "new value for ${user_var} --> $user_value"
# *** This is failing.. How can I change say
# myvar1 value to 'mytest4' !!?
$((user_var))=$user_value
fi
done # End of - select
done # End of while
# EOF
Code:
$>testscript.sh
......< Menu > .........
To Change Above Defaults Make A Selection:[n] 4
Set --> cvsRepositoryUserID ?: n
new value for myvar1 --> n
testscript.sh[]: myvar1: bad number
Last edited by Franklin52; 04-29-2010 at 06:36 PM..
Reason: Please use code tags!
Hello,
Can somebody please give me a snippet for the below requirement.
I want to assign the values separeted by a comma to be assigned to a dynamic array.
If I give an input (read statement) like abc1,abc2,abc3,abc4,abc5, all these strings abc* should be assigned to an array like below... (2 Replies)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
1) Write a Menu Driven Shell Script which accepts1 to 5 options and performs the following actions for... (1 Reply)
Hi Guys..
am new to unix scrpiting..I need a Menu need to create using shell scrpting
eg:
Food items
ready
paid
if i press "f" need to add items for a file food items..
if i press "r" it need to move into ready and remove from food items
if i press "p" need to update a filed in... (1 Reply)
i'm confused what this means.
i was asked to design a menu or command line option driven script that reads out of a DB and displays info such as
read_data.pl -u <user> -e <event>
which would print commands run by <user>with the <event> in the db.
any suggestions? i've been using... (2 Replies)
Hi, I was wondering if someone could help me write a shell script in Linux that backsup/restores data to anywhere I choose but it needs to be menu driven?
Thanks, I'm new to Linux/Unix but liking it so far...just hoping to get to grips with the scripts! :) (7 Replies)
I'm a beginner at scripting and have been putting this script together over the past week. It's no where as polish as it could be. Any tips/suggestions on improving this script would be appreciate it. Every week, my team develops WAR files in tomcat on our test environment and moves them to our... (4 Replies)
Hi! This might be a simple thing, but I'm struggling to assign values to variables from the file.
I've the following values stored in the file.. It consists of only two rows..
10
20
I want to assign the first row value to variable "n1" and the second row value to variable "n2"..
That is ... (3 Replies)
My employers would like me to selectively run one of several different (already-existing) Korn Shell menu-driven scripts out of the user's .profile file, depending on some yet-to-be-specified user critieria.
I've never done this kind of thing, but I have the existing scripts (among other... (5 Replies)
Hi All,
I have written a menu driven bash shell script.
Current Output is as below:
-------------------------------------
Main Menu
-------------------------------------
Option 1
Option 2
Option 3
Option 4
Exit
=====================================
Enter your... (3 Replies)
Hi Team ,
I wrote a shell script for adding and subtracting two numbers am getting error could some one please help to fix it
script:
echo "Enter 1 to add:"
echo "Enter 2 to sub:"
echo "Enter 3 for both addition and subtraction :"
read ans;
case "$ans" in
1)... (4 Replies)