Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Pattern substitution. The pattern is expanded to produce a pattern just as in pathname expansion. Parameter is expanded and the longest match of pattern against its value is replaced with string. If pattern begins with /, all matches of pattern are replaced with string. Normally only the first match is replaced. If pattern begins with #, it must match at the beginning of the expanded value of parameter. If pattern begins with %, it must match at the end of the expanded value of parameter. If string is null, matches of pattern are deleted and the / following pattern may be omitted. If parameter is @ or *, the substitution operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with @ or *, the substitution operation is applied to each member of the array in turn, and the expansion is the resultant list.
yes this is perfect but in my case i have pass this for a sh file from prompt as
Code:
./sh pass="asdf-)"
this will be treated as asdf-) in bash. Then i am calling another sh file, where i am using expect (password). there i cannot change value fro ')' to '.'
#!/usr/bin/expect -f
.
.
.
set p [lrange $argv 0 0]
.
.
.
send -- "echo correct script \r"
send -- "echo valu passwrd 0 argument = $p \r"
set send_human {.1 .25 2 .05 1.5}
set breaktheloop 0
while {$breaktheloop == 0} {
expect "*Password:*"
send -h "$p\r"
expect -timeout -1
sleep 10
set breaktheloop 1
the main idea is to pass the password as a parameter.
the problem is because of the special character ')'. it is correctly interpreted in main.sh. But when it goes to second shell file which is to handle expect utility, it does not recognize '\' as escape character. it treats "p:-\)10" as 7 character string but actually my password is 6 character string "p:-)10".
Why this construct? It seems you need to split the pass part from the "p:-\)10" part inside your script.
Wouldn't ./main.sh "p:-\)10" (or ./main.sh 'p:-)10') be easier? Inside the script you can do: PASS="$1"
If you put single quotes around the input instead of double quotes, you do not need to escape the ) when starting the main script.
Quote:
Originally Posted by xombboxer
from main.sh again im calling one more sh file
Code:
../_exp.sh $PASS
Do you need to call a second script? Can't you incorporate the expect part into your first script? This way you can use the vars that are used in both the bash and the expect part.
Code:
#/bin/bash
.
bash stuff goes here
.
expect -c "
.
expect stuff goes here
.
"
more bash stuff
This way you won't need the set p [lrange $argv 0 0] part and can use $PASS instead of $p (send -h "$PASS\r")
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.