cant get variable outside "while" in ssh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cant get variable outside "while" in ssh
# 1  
Old 07-24-2012
Question cant get variable outside "while" in ssh

Hi all
I have a problem with this var Smilie
I dont know why I cant get it ?!!?!
Im trying with

Code:
newvar1=$(($var+1))
newvar1=$(($var + 1))
newvar1=`expr $var + 1`

expr: syntax error
expr: syntax error
expr: syntax error

but it not work Smilie in other script its ok and working
tell me where is the problem pls?

Code:
awk  '/<iframe /{p=1} /<\/iframe>/{p=0; next}!p' |  while read myline; do

newvar1=${myline}

done
echo $newvar1


Thank you!!!

Last edited by sanantonio7777; 07-24-2012 at 06:59 PM..
# 2  
Old 07-24-2012
It's because of the pipe.

The while loop executes inside a subshell, and doesn't affect variables in the shell outside it.

What are you actually trying to do?
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 07-24-2012
ok thank you !

I want to get all lines from the while loop to >> $newvar1

any ideas how to make it ?
# 4  
Old 07-24-2012
And why are you trying to get all the lines from your while loop into newvar1?

What are you actually trying to do?

There may be more direct ways, is what I am thinking, if only I knew what you were actually doing. Usually feeding a single line through awk is a mistake.
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 07-24-2012
ok
this is the full source code

Code:
echo "$result_get"|awk  '/<iframe /{p=1} /<\/iframe>/{p=0; next}!p' |  while read myline; do
then
newvar1=${myline}
fi
done
echo $newvar1

I just wanna give all the lines from while loop in $newvar1 to use it as a var for checking...

Thank you!

Last edited by sanantonio7777; 07-24-2012 at 06:58 PM..
# 6  
Old 07-24-2012
And why are you trying to get all the lines from your while loop into newvar1?

What are you actually trying to do? What is the function of that awk, there?

I am not diverting you or trying to be mean, the question is relevant. I don't actually know what your script does, so it's hard to help it, but the best way to allow the inside of the loop to set variables would be to remove that pipe.

Doing that means changing the logic of your program.

Changing the logic of your program means understanding your program.

Understanding your program means seeing what it's supposed to be doing.

Please explain.
This User Gave Thanks to Corona688 For This Post:
# 7  
Old 07-24-2012
Code:
awk  '/<iframe /{p=1} /<\/iframe/{p=0; next}!p'

this remove <iframe></iframe> tags from $result_get or inputfile

next I count the words in every line
and I want to get all the lines with more than 20 words
in one var outside the loop
thats all...
I will change the pipe .. thank you !

Last edited by sanantonio7777; 07-24-2012 at 06:58 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. Red Hat

Use variable that needs "" in remote ssh command.

I want to use the below but since the date has a space it doesn't grep exactly what's needed. I need to keep the quotes around the variable when it passes it. I need the quotes around $DATE2 just to recognize the variable. Thanks in advance for any help given. D=`date +%d` DN=`echo -n $D |... (3 Replies)
Discussion started by: toor13
3 Replies

4. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

5. UNIX for Dummies Questions & Answers

What is the significance of sh -s in ssh -qtt ${user}@${host} "sh -s "${version}"" < test.sh?

Please can you help me understand the significance of providing arguments under sh -s in > ssh -qtt ${user}@${host} "sh -s "${version}"" < test.sh (4 Replies)
Discussion started by: Sree10
4 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

if [ "variable" = "numerical-range" ]; then

been a while so i'm a bit rusty and need a little help. writing a script that needs to compare $EXECHOST(a number) against a numerical range and then set a value. below isn't working but should give you folks an idea of my goal: if ; then echo "This is a 32B machine, exiting..." if ;... (4 Replies)
Discussion started by: crimso
4 Replies

8. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

9. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question