I have an variable by name dir.If i do echo $dir i will get the path (/usr/bin/).
I am writing a shell script which will prompt to enter the variable name if run.Suppose the script name is test.sh.
If run test.sh it will prompt for entering variable name which is dir.Suppose if i do echo $dir inside the shell script it is not giving me the path.looks like it passing the value entered as a literal string.
How can i get the actual value of variable dir inside the script.
Your main problem is that your echo commands, which you assumed were going to the tty, were going to the read in the main body of the script. By redirecting them to stderr, the prompt and other information go to the tty, while the echo goes into VariableName.
You could also code
since you are only capturing the output into a single variable. This would work in bash as well as kshell. The echo/printf commands still need to be redirected; it's just an alternate approach.
I changed your echo -n to a printf command. Echo has so many different implementations that when I need to do something other than normal (e.g. adding the -n) I use printf. Just a preference of mine and no real bearing here.
---------- Post updated 04-27-12 at 00:10 ---------- Previous update was 04-26-12 at 23:51 ----------
I did have a go with your original script, and regardless of function definition style, function name, or name(), it works for me in both Kshell and bash. Given that your kernel seems pretty old, I'm wondering if you don't have a very old shell too. If you continue to have issues, it might be interesting to know what version of the shell you are running. Try excuting the command echo ${.sh.version} at the command line, or ksh --version.
Last edited by agama; 04-27-2012 at 12:57 AM..
Reason: code tag issue
If the O/P has ksh as stated in a reply to one of the questions, the original script in post #1 should work. We need the O/P to check which Operating System and Shell is actually in use here.
Hi everyone,
Is it possible to define blank vaianbles and prompt user to fill them during the script execution?
A very simple example:
INPUT=
OUTPUT=
cut -f1-4 $INPUT | sed 's/hello/goodbye/g' | sort -uV > $OUTPUTThank you in advance!
Best wishes (2 Replies)
I am executing a shell script which contains a jar call to an external java package for which I don’t have a read access to. The external package was written in such a way that whenever we make a java –jar call to the package, it shows a prompt on the console asking if we want to continue or no... (1 Reply)
Hi All,
I have a file which has hundred of records with fixed number of fields. In each record there is set of 8 characters which represent the duration of that activity. I want to sum up the duration present in all the records for a report. The problem is the duration changes per record so I... (5 Replies)
I am writing a scritp in which first step is to get some files from a server.
I am using mget to do that.
here is my FTP code ...
HOST="XXX.XXX.com"
28 ftp -inv $HOST <<END &> $FTP_LOG
29 quote USER $USER
30 quote PASS $PASWD
31 cd log
32 prompt off
33 binary
34 mget... (0 Replies)
Hi all - I am totally stuck here :wall
I have been asked to write a shell script that does a few little things and then reads from a config file and kicks off an instance of another script, say scriptB.ksh for each line in the config file. These should all be run in parallel. This is all fine but... (2 Replies)
Hi,
Please let me know how to reassign value to a variable.The calling script is passing parameter as HAT_DIV but I like to pass HAT DIV ( two words) to DIV parameter.These are .ksh scripts.
# access to target - (user passwd sid) must be provided.
USER=$1; ... (5 Replies)
Hi!
I am using latest ZSH and I have setopt prompt_subst
I have a global hash array variable which contains some color definitions with color names as keys and 256-color ANSI codes (with %{ and %}) as values, eg %{\ePS1="$FG Hello World (%M) > "
or
PS1=$'$FG Hello World (%M) > '
then it... (3 Replies)
Hi,
I am using git bash terminal window to do git operations. I have set the prompt string variable PS1 in the ~/.bashrc file as follows:
export PS1=" "
This is intended to show me the current git branch's name which is active as part of the prompt string. But, the problem is when I do a git... (2 Replies)
Hi,
My variable has value as this:
tvar1="bool_risk_enabled" Boolean "true"
Now I need to replace this true with false. Which is the best way to do this? Can we do this with sed command?
Please help me.
---------- Post updated at 05:23 PM ---------- Previous update was at 05:00 PM... (2 Replies)
I want to install pecl from a single command without it asking me for a response of "yes" or "no" to finish the install...
--------------------------------------------------------------------------
# pecl install pecl_http
downloading pecl_http-1.7.0.tgz ...
Starting to download... (1 Reply)