Basicly, i want to make sure that entry is made (i can add more sophisticated checks later), but the idea is to recycle the same function "assign_var" many times over.
i.e.
And needless to say, the variable must be global and accessible later.
$1 is never -z because it's the literal string '$IPADDRESS' or whatever. You can't do "pointer" like variables that way. You can do VARNAME="QWERTY" ; echo ${!VARNAME} to get the contents of ${QWERTY} though, so, how about:
so you can reuse your code reuse Just add more data lines to varlist instead of repeating read_var over and over.
It will never prompt for variables that're already set, you should know.
Last edited by Corona688; 09-07-2011 at 03:59 PM..
You are correct and my mistake, i got the first email at 2:51pm and used the sample i saw in the email.
This version does work but adds a minor over head - would you know of a way to get my sample code to work. The idea is to keep it simple using functions and recycle the same function over and over again that inturn sets up variables for each argument passed into a function.
Thanks for the help, i got it to work and decided to take it step further. I'm hoping you would know what i'm doing wrong.
I would like for the user to be prompted, but if value for variable exists, display it in brackets and if user presses enter without modifying the string, the same value is used for that variable. However, in my attempt to headlock $1=$var within function and if/else statement fail with "command not found".
Output IPADDRESS: [testhost1] ./main.sh: line 23: DHCPIPADDRESS=testhost1: command not found
My code (i begin adding tempvars in attempt to debug and resolve the issue, but havenot had much luck)
Also, i'd like to fill the gap in this area, what is this concept called and where would i find more details on it? My basic google search did not yield any results, but i'm guessing my keywords arent correct.
I have a script that uses 2 arguments. I want to call the function part within this script using these same arguments. Below is what I came up with below script so far, any guidance would be helpful. Thank you!
cat backup.sh
#!/bin/bash
function usage {
echo "USAGE: $(basename $0)... (6 Replies)
I'm reading Wicked Cool Shell Scripts. For some reason, the function pasted in below gives the error: ./inpath2: line 10: in_path()
4 {
5 cmd=$1 ourpath=$2 result=1
6 oldIFS=$IFS IFS=":"
7
8 for directory in "$ourpath"
9 do
10 if ; then
11 result=0
12 fi... (9 Replies)
Heays
So i have that script to which i'd like to pipe (rather than just regular arguments) some data from another virtual output command.
Simplified:
echo * | script.sh
When i know how many args i expect, i can handle this simple by:
&& \
read ONE TWO && \
set ONE TWO
echo "$1 : $2... (7 Replies)
Hi.
How can I create a history function? (By "read" command or so)
&
How can I configure a read command so that the arrow keys are not displayed so funny? (^[[A)
Thanks in advance. (4 Replies)
Hello Everyone,
Is there a way i can pass the arguments as parameters or variables instead of positional arguments to a function, below i am calling the function defined in a script.
Call:
notify "Error While Generating The List File: ${GEN_PARAM_LIST9} For Feed Data Validation Errors In... (1 Reply)
I need to call a function within a code with $database and $ service as the arguments How do I proceed ? and how would a function be defined and these two arguments would be used inside the function?
calc_pref_avail $database $service
Best regards,
Vishal (7 Replies)
I'm putting together a script that will search my mail archives for emails that meet certain criteria and output the files to a text file.
I can manually cat that text file and pipe it into sendmail and it will work (i.e. cat /pathtofile/foo.txt | sendmail -t me@company.com)
My script sends... (7 Replies)
Hi Guys,
I am trying to pass arguments to the script i am wrinting.
When no argument is passed or wrong argument is passed, the script needs to output the way it needs to be called and exit.
Currently, when no arguments is passed, it is not getting exited but goes on assuming those... (3 Replies)
Hi,
I've a logging function in bourne shell, flog() which logs the first argument passed to it. How can I pass arguments to this function from a file, like
cat filename | sed '...filtering...' | flog
or
cat filename | sed '...filtering...' | xargs flog
Which did not work, after which... (3 Replies)
hi
i have a function
abc
{
//from this function i am passing args to antoher function like
def a b c j k l
}
now i want to count the no of args coming to def() function and iterate over those values
is there any way to do this one
please help (2 Replies)