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 03-16-2020, 10:01 AM   #1
motherboard
LQ Newbie
 
Registered: Jun 2018
Posts: 12

Rep: Reputation: Disabled
How to pipe only 1 $i?


for i in mirror.foo ; do echo $i $i | rev ; done
oof.rorrim oof.rorrim

How do I get rev to pipe only the second $i?

The outcome should look like this

mirror.foo oof.rorrim
 
Old 03-16-2020, 10:13 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Code:
man echo
hint, -n is your friend.
 
Old 03-16-2020, 10:16 AM   #3
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Another method in bash is to make use of the $() construct to execute a command "in-line"
 
Old 03-16-2020, 10:16 AM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
There are multiple ways.
Command substitution is another hint.

Replied to late...
 
Old 03-16-2020, 03:55 PM   #5
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,137
Blog Entries: 6

Rep: Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826
Quote:
for i in mirror.foo ; do echo $i $i
That will echo the same line twice. Why are you doing that?

Quote:
The outcome should look like this

mirror.foo oof.rorrim
Code:
mirror_foo="oof.rorrim"

for i in mirror_foo; do
    echo ""$i" "${!i}""
done

mirror_foo oof.rorrim
Is mirror.foo a variable or a file name?
. is not allowed in a bash variable.
 
  


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
[SOLVED] How to handle a broken pipe exception (SIGPIPE) in FIFO pipe? zyroot998 Programming 5 03-03-2011 08:10 PM
PING .... pipe 2 vs pipe 3 hanen03 Linux - Networking 1 04-10-2009 10:50 AM
pipe using no pipe soathana Programming 2 02-22-2003 04:33 PM

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

All times are GMT -5. The time now is 08:07 PM.

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