LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 09-27-2021, 08:37 PM   #1
packets
Member
 
Registered: Oct 2005
Posts: 339

Rep: Reputation: 32
Newline for arguments. Is that possible?


We have application that feeds to a script. It has 3 variables and I am passing it as arguments.

script_name $1 $2 $3

The $1 and $2 is a string while $3 consist of bunch of strings with new line. I notice if there is new line, it was not able to receive properly but if it is a one line there is no issue.

Any recommendation or is it not possible to use argument with new line?
 
Old 09-27-2021, 10:09 PM   #2
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,150

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
Check out this link declare the variable as an array.

https://stackoverflow.com/questions/...an-empty-array

list=$@

then try script_name "$@" or $list

check out this one also: https://tldp.org/LDP/abs/html/arrays.html

not tested

Last edited by JJJCR; 09-27-2021 at 10:09 PM. Reason: edit
 
Old 09-28-2021, 02:32 AM   #3
packets
Member
 
Registered: Oct 2005
Posts: 339

Original Poster
Rep: Reputation: 32
Thank you. Will check it

Quote:
Originally Posted by JJJCR View Post
Check out this link declare the variable as an array.

https://stackoverflow.com/questions/...an-empty-array

list=$@

then try script_name "$@" or $list

check out this one also: https://tldp.org/LDP/abs/html/arrays.html

not tested
 
Old 09-28-2021, 07:30 AM   #4
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,599

Rep: Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546

The Bash manual is one of the best sources of information on shells (even if using a non-Bash shell; it splits the POSIX and Bash-specific stuff out). Section 3.1 is relevant here.

There's also the BashFAQ, and again you really should read and understand the "Arguments" page.

 
3 members found this post helpful.
Old 09-30-2021, 01:46 PM   #5
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,792

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
The key is quoting.
Code:
script_name "$1" "$2" "$3"
or the adaptive
Code:
script_name "$@"
 
1 members found this post helpful.
Old 09-30-2021, 11:51 PM   #6
Brains
Senior Member
 
Registered: Apr 2009
Distribution: All OS except Apple
Posts: 1,591

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Quote:
Originally Posted by boughtonp View Post
The Bash manual is one of the best sources of information on shells (even if using a non-Bash shell; it splits the POSIX and Bash-specific stuff out). Section 3.1 is relevant here.

There's also the BashFAQ, and again you really should read and understand the "Arguments" page.

You're not much help.
Forums exist because the majority of people would rather not waste time reading.
 
Old 10-01-2021, 01:17 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,848

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
Quote:
Originally Posted by Brains View Post
You're not much help.
Forums exist because the majority of people would rather not waste time reading.
That statement is wrong. People need to read anyway, either the original page or the forum. But without reading it won't work.
Copying huge amount of text into LQ is meaningless too.

Anyway, this is a problem with quotation (of arguments). You can either drop in a quick-fix (without comments) or try to explain what went wrong and how can anyone fix it - not only now, but next time too.
Additionally you can suggest external sites (like shellcheck) to analyze the script and help without waiting for any kind of response here.
 
1 members found this post helpful.
Old 10-01-2021, 01:37 AM   #8
Brains
Senior Member
 
Registered: Apr 2009
Distribution: All OS except Apple
Posts: 1,591

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Quote:
Originally Posted by pan64 View Post
That statement is wrong. People need to read anyway, either the original page or the forum. But without reading it won't work.
Copying huge amount of text into LQ is meaningless too.

Anyway, this is a problem with quotation (of arguments). You can either drop in a quick-fix (without comments) or try to explain what went wrong and how can anyone fix it - not only now, but next time too.
Additionally you can suggest external sites (like shellcheck) to analyze the script and help without waiting for any kind of response here.
The reason I don't ask questions is because Google is my homepage, I know how to read and comprehend what I read.
People with a life beyond the keyboard would rather spend more time doing life.
 
Old 10-01-2021, 06:35 AM   #9
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,599

Rep: Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546
Quote:
Originally Posted by Brains View Post
You're not much help.
Forums exist because the majority of people would rather not waste time reading.
LQ exists [in part] so people can be pointed at the correct places to read, and not waste time reading inaccurate or outdated information.
Quote:
Originally Posted by https://www.linuxquestions.org/questions/faq.php?faq=welcome
please understand that LQ is not a help desk, customer service line for a product you purchased or willing to do your homework (although we are happy to assist you with specifics, if you show some effort of your own!). We're a 100% volunteer organization that wants to help you help yourself.

(Forums exist as an evolution of earlier technologies, bringing the advantages of hypertext without bias on how proactive/lazy its posters may or not be.)


Last edited by boughtonp; 10-01-2021 at 06:36 AM.
 
1 members found this post helpful.
Old 10-01-2021, 11:49 AM   #10
cynwulf
Senior Member
 
Registered: Apr 2005
Posts: 2,727

Rep: Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367
Quote:
Originally Posted by Brains View Post
People with a life beyond the keyboard would rather spend more time doing life.
You seem to speak for others, in particular a certain type of user who puts in little effort, but instead leeches off others. By that you imply that the leeches have a "life" and those providing help do not [thus they have the time to support the leeches].

I see it slightly differently in that proprietary OS and paid support for distributions such as RHEL exist for example...
 
1 members found this post helpful.
Old 10-02-2021, 06:19 AM   #11
Brains
Senior Member
 
Registered: Apr 2009
Distribution: All OS except Apple
Posts: 1,591

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Quote:
Originally Posted by cynwulf View Post
You seem to speak for others, in particular a certain type of user who puts in little effort, but instead leeches off others. By that you imply that the leeches have a "life" and those providing help do not [thus they have the time to support the leeches].

I see it slightly differently in that proprietary OS and paid support for distributions such as RHEL exist for example...
What I'm saying:
Your average 5 year old can do that, Google up the literature and post some links:
"Here you go idiot, I did the hard work for you" as if to imply the OP didn't have brains enough to figure out the proper keywords to Google it on their own. The OP likely either saw the links or visited them already.

I see that as being snotty rather than helpful.
 
Old 10-02-2021, 07:34 AM   #12
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,848

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
Quote:
Originally Posted by Brains View Post
I see that as being snotty rather than helpful.
And this is just wrong. This is when you want to reject the help even before you get it.
 
Old 10-02-2021, 07:41 AM   #13
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,599

Rep: Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546

Brains, you may like to remind yourself of the LQ rules, particularly the top portion of bullet points.

If you think my post violated the rules, feel free to report it to the moderator. (I doubt they agree with you, but maybe I'm wrong; I welcome constructive feedback.)

If you think the rules need to be updated to prohibit linking to relevant documentation, go ahead and start a discussion in LQ Suggestions & Feedback, where it will not be taking a thread off-topic.

On which note...

packets: If you have any follow-up questions or clarification needed about passing arguments to a script (whether individually, as arrays, whatever), please do to post them; otherwise you might like to use Thread Tools to mark the thread as solved.


Last edited by boughtonp; 10-02-2021 at 07:44 AM.
 
Old 10-04-2021, 08:38 AM   #14
cynwulf
Senior Member
 
Registered: Apr 2005
Posts: 2,727

Rep: Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367
Quote:
Originally Posted by Brains View Post
What I'm saying:
Your average 5 year old can do that, Google up the literature and post some links:
"Here you go idiot, I did the hard work for you" as if to imply the OP didn't have brains enough to figure out the proper keywords to Google it on their own. The OP likely either saw the links or visited them already.

I see that as being snotty rather than helpful.
There are certainly web users who post "google it" and have the kind of attitude you allude to - I've seen it elsewhere where they can become prolific posters if allowed to run unchecked, such as the Debian forums some years ago for example, not so much here at LQ - and I'm very much of the same view that you are, when it comes to such web users.

boughtonp's post does not fit that category. That post does not contain advice to use a search engine, nor links to search engines - it contains links to documentation and it's informative. In my view you've shot from the hip, and should reconsider your response.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
match newline, space, newline vincix Programming 13 03-09-2017 03:14 PM
[SOLVED] C Program in Bash :Passing Newline in Command Line Arguments tuxtuxtux Programming 13 02-14-2014 03:18 AM
[SOLVED] How to replace newline pattern in file by other newline pattern in a shell script XXLRay Linux - Software 9 11-29-2010 07:57 AM
Figured you guys may know.. Conky, possible to list multiple interfaces as arguments? Mysticle31 Programming 0 01-08-2008 05:23 PM
VI replacement: newline for newline not working! jhwilliams Linux - Software 3 08-16-2007 06:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration