You are not logged in.
Hello there
in shellscript I have 2 variables let's say $fruit and $color
echo $fruitsoutputs:
banana
apple
lampoonand
echo $coloroutputs
yellow
red
purpleI need to output
banana yellow
apple red
lampoon purpleinstead of
banana
apple
lampoon
yellow
red
purpleThanks
Last edited by kitalia (2022-01-16 17:33:59)
Offline
shellscript as in POSIX sh only? If you're using bash, I would put them into an array and address them individually. Otherwise, you can make it happen with sed.
Offline
yep posix, how can I use sed for that?
Offline
Something like `echo "$fruits" | sed -n 1p` will print the first line of the given variable. Not hard to build things from there.
Last edited by Scimmia (2022-01-16 16:46:52)
Offline
that outputs only the first line....if I knew how to proceed from there I wouldn't ask for help....I could have just googled 'how to print only first line shellscript" ....
Last edited by kitalia (2022-01-16 16:52:57)
Offline
You can't build it from there?
What are you actually doing, anyway?
Offline
I thought it was clear what my end goal is
Offline
Not really. If you can't build it from there, it sounds like you have no idea about shell scripting at all, making me think this is homework.
Offline
I need to output
banana yellow
apple red
lampoon purple
and I'm 33, 100% self thaught and asking for in the NEWBIE section, this explains why I do not know how to make very simple things that people with regular education in IT might think as stupid easy but even if it was homework what's the point? I need any specific skill level or certificate to ask a newbie question?
you need any more personal info? Maybe my ssn
obviously this is mock up data, i do not need to sort fruits/colors :-) this is part of a ~300 lines shellscript
Last edited by kitalia (2022-01-16 17:10:11)
Offline
I'd like to know where the content of these "variables" are coming from, because this is clearly an X-Y problem. I say this is clear, as the commands and output you provided are not real: you've provided them as a fictional example as they could not generate that output as written. Shell expansion of the variable passed to echo will result in a collapsing of whitespace (including newlines); so the only way you'd even get the output you are currently getting is by making up the examples and fictional output rather than it being something you actually ran.
This is not nitpicking as it is most likely relevant. If these "variables" are actually the results of some other process, you'd probably want to use the command `paste`. So what are you really trying to do?
... even if it was homework what's the point?
The point is, we will not do people's homework for them. It is a violation of our rules as it undermines the goals of educational programs.
obviously this is mock up data, i do not need to sort fruits/colors
Ah, yes, as I already noted above: obviously it is. But is it so "mocked up" as to be meaningless. Tell us what you really need to do.
Last edited by Trilby (2022-01-16 17:15:47)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
yep this is mock up data and it's the result of other processes
how can I do it with paste? never used it
I'm using curl and sed until I get the desired data, queries are determined by user input read
Last edited by kitalia (2022-01-16 17:15:43)
Offline
RTFM.
Saying you're using curl and sed doesn't mean much. Is this top secret, or some proprietary 300 line shell script? We really don't care what flavor of porn your script is downloading - but if you will not share actual code, it's not likely that you will be able to get helpful answers.
Last edited by Trilby (2022-01-16 17:19:48)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Also (because I don't trust you t know the difference between posix and bash and it becomes ABYSMALLY simpler w/ the latter):
declare -p fruitsOffline
to whomever will stumble upon the same issue, here's the super secret answer the elitist arch community won't provide to newbies:
paste <(echo "$fruit") <(echo "$color")omg do you understand that a working example will be indexed and people with the same question will find it?
RTFM.
Saying you're using curl and sed doesn't mean much. Is this top secret, or some proprietary 300 line shell script? We really don't care what flavor of porn your script is downloading - but if you will not share actual code, it's not likely that you will be able to get helpful answers.
I might have a 1000 different reasons not to share why or how the script works (which is open source FYI), you have 0 reasons to be condescendent about it
also the manual didn't say much, found the answer on stack overflow.
And this ladies and gents is why people say the Arch community is toxic.
Last edited by kitalia (2022-01-16 17:47:25)
Offline
Also (because I don't trust you t know the difference between posix and bash and it becomes ABYSMALLY simpler w/ the latter):
declare -p fruits
Thank you, I thaught myself every single thing I know about IT, I don't know shit, thank you.
Offline
to whomever will stumble upon the same issue, here's the super secret answer the elitist arch community won't provide to newbies:
paste <(echo "$fruit") <(echo "$color")
That's process substitution, and is not defined by POSIX, so it doesn't meet your requirements.
Offline
kitalia wrote:to whomever will stumble upon the same issue, here's the super secret answer the elitist arch community won't provide to newbies:
paste <(echo "$fruit") <(echo "$color")That's process substitution, and is not defined by POSIX, so it doesn't meet your requirements.
If you have a better solution that accomplishes the same result please feel free to share, thank you
Last edited by kitalia (2022-01-16 17:53:02)
Offline
Posix heredocs, but that's a complete pita and also why the very first thing you were asked was whether this is bash or posix, which you falsely answered to be posix.
Offline
Posix heredocs, but that's a complete pita and also why the very first thing you were asked was whether this is bash or posix, which you falsely answered to be posix.
thank you but this doesn't really solve the issue, if you too have a solution please feel free to share!
Offline
Yes, please only post if you can give them something they can copy and paste, as it seems like that's the only thing they're capable of here.
Offline
The issue is that we're still unclear about your requirements and that "we" includes "you"
Last edited by seth (2022-01-16 18:01:36)
Offline
Yes, please only post if you can give them something they can copy and paste, as it seems like that's the only thing they're capable of here.
Yes thank you, you are super special and knowing the inner workings of everything puts you on top of me as human being!
Offline
The issue is that we're still unclear about your requirements and that "we" includes "you"
I'd like to achieve the same result as
paste <(echo "$fruit") <(echo "$color")in a posix compliant way do you know how to?
Offline
to whomever will stumble upon the same issue, here's the super secret answer the elitist arch community won't provide to newbies:
It's so fucking secret that it's precisely what I told you you'd probably want to use in my first reply.
You're selfish, rude, ungrateful, and abusive to the people who you ask for help. Think whatever the hell you want of this community, as long as you leave it: you are not welcome here.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Echo the variables into temporary files?
Again, posix heredoc is going to be a complete pita
Offline