Sponsored Content
Full Discussion: Retaining value outside loop
Top Forums Shell Programming and Scripting Retaining value outside loop Post 303031434 by knowyrtech on Thursday 28th of February 2019 08:21:07 AM
Old 02-28-2019
Quote:
Originally Posted by nezabudka
Hi,
maybe so
Code:
totalstr=$(grep -o "\S\+" <<<"$loc" | paste -sd,)
echo "Final Output:$totalstr"

Tried this suggestion but i see nothing empty output:

Code:
more list.sh
#!/bin/bash

loc=$1

totalstr=""

totalstr=$(grep -o "\S\+" <<<"$loc" | paste -sd,)

echo "FINAL:$totalstr"

Quote:
OUTPUT:
/opt/myscripts/list.sh 'string1
string2
string3
'
FINAL:
My system is Linux.

Please suggest.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Retaining value in var for flag.

I have problem like this : while loop 1 var=some expression 2 if then 3 Do something 4 oldVar=$var 5 fi 6 done Then, I am facing error at line number 2, mentioning invalid argument. Can anyone please help me for, How to retain value in oldVar? (4 Replies)
Discussion started by: videsh77
4 Replies

2. Shell Programming and Scripting

variable not retaining value

Bourne shell Solaris I'm trying to set a flag to perform an action only when data is found. So I initialize the flag with: X=0 Then I read the data: if ; then while read a b c do X=1 done < ${inputFile} fi The problem is that X will be set to 1 inside the while loop but when... (5 Replies)
Discussion started by: gillbates
5 Replies

3. Shell Programming and Scripting

Retaining tar.gz after gunzip

gunzip fnam.tar.gz After this command execution... .gz file no longer exists... and only fnam.tar is present. Is it possible to retain the tar.gz file after after using the above command thx in advance. (4 Replies)
Discussion started by: devs
4 Replies

4. Linux

retaining the evironment varaibles...

Hi all, I wrote a shell script in which one of the if condition i tried to set few variables and exported them...and when i am out of if condition i wish to run one of my script which uses those variables exported. But i found that when i am out of the if statement those variables... (5 Replies)
Discussion started by: priya444
5 Replies

5. UNIX for Dummies Questions & Answers

Retaining Spaces within a word

Hi Experts, I have a 2 GB flat file which have unicode field, some of them are blanks and its size is 4000 character. In the existing system SED command removes the spaces. Because of this field itself....it is taking almost three days to complete the file processing. I removed sed and... (0 Replies)
Discussion started by: RcR
0 Replies

6. Shell Programming and Scripting

retaining file path

hi all, Is there any way to retain file path? echo "Please enter your old filename" read a #user input : /blah/blah1 echo "please enter the new filename" read b #user input : dumb mv $a $b What i would like to do is for the user to enter just the "filename" for the new filename... (2 Replies)
Discussion started by: c00kie88
2 Replies

7. Shell Programming and Scripting

help in retaining leading zero

Hello. I'm trying to add multiple numbers with varying length and with leading zeroes in it. However, I'm getting the sum (totalHashAccountNumber) without the leading zeroes in it. How do I retain the leading zeroes? Please pardon the lengthy code.. I'm getting the hash account number from 2... (2 Replies)
Discussion started by: udelalv
2 Replies

8. Shell Programming and Scripting

Perl: Problem in retaining values after each loop

use strict; use warnings; open (my $fhConditions, "<input1.txt"); #open input file1 open (my $fhConditions1, "<input2.txt");#open input file2 open (my $w1, ">output1"); open (my $w2, ">output2"); our $l = 10;#set a length to be searched for match our $site="AAGCTT";#pattern to be matched... (1 Reply)
Discussion started by: anurupa777
1 Replies

9. Shell Programming and Scripting

Retaining whitespaces...

There's an input file(input.txt) which has the following details : CBA BA <Please note the second record has a LEADING WHITESPACE which is VALID> I am using the following code to read the content of the said file line by line: while read p ; do echo "$p" done < input.txt This is the... (1 Reply)
Discussion started by: kumarjt
1 Replies

10. Shell Programming and Scripting

Retaining latest file

Hi All, I have a requirement where there are 2 files saved on unix directory with names anil_111 and anil_222. I just have to retain the latest file and delete the old file from the directory. Please help me with the shell script to perform this. Thanks, Anil (7 Replies)
Discussion started by: anil029
7 Replies
break(1)                                                           User Commands                                                          break(1)

NAME
break, continue - shell built-in functions to escape from or advance within a controlling while, for, foreach, or until loop SYNOPSIS
sh break [n] continue [n] csh break continue ksh *break [n] *continue [n] DESCRIPTION
sh The break utility exits from the enclosing for or while loop, if any. If n is specified, break n levels. The continue utility resumes the next iteration of the enclosing for or while loop. If n is specified, resume at the n-th enclosing loop. csh The break utility resumes execution after the end of the nearest enclosing foreach or while loop. The remaining commands on the current line are executed. This allows multilevel breaks to be written as a list of break commands, all on one line. The continue utility continues execution of the next iteration of the nearest enclosing while or foreach loop. ksh The break utility exits from the enclosed for, while, until, or select loop, if any. If n is specified, then break n levels. If n is greater than the number of enclosing loops, the outermost enclosing loop shall be exited. The continue utility resumes the next iteration of the enclosed for, while, until, or select loop. If n is specified then resume at the n- th enclosed loop. If n is greater than the number of enclosing loops, the outermost enclosing loop shall be used. On this man page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Words that follow a command preceded by ** that are in the format of a variable assignment are expanded with the same rules as a vari- able assignment. This means that tilde substitution is performed after the = sign, and also that word splitting and file name genera- tion are not performed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), exit(1), ksh(1), sh( 1), attributes(5) SunOS 5.10 17 Jul 2002 break(1)
All times are GMT -4. The time now is 12:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy