LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 07-21-2012, 06:48 AM   #1
ofer4
Member
 
Registered: Apr 2012
Posts: 100

Rep: Reputation: Disabled
end of line bash


hi

in c++ we cna print <<endl, which mean end of line

how can i do implement it in bash script?

for example this program:

Code:
#!/bin/bash

num=$#

for ((i=0;i<=num;i++))
do
   echo "$1"
   shift
   echo "$2"
   shift
done;
i want that this program will print:

Code:
Print-pairs ab cd ef gh
the out[ut will be:

Code:
ab cd
ef gh
every two parameters will prints in one line

thanks all
 
Old 07-21-2012, 07:17 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
http://www.tldp.org/LDP/abs/abs-guide.pdf

See page 44
 
Old 07-21-2012, 08:14 AM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,456

Rep: Reputation: 445Reputation: 445Reputation: 445Reputation: 445Reputation: 445
echo is a bit problematic: it has different implementations, and not all of them has '-' option (meaning: no more options), so 'Print-pairs -n Hello' would do something else than you would expect.

Code:
do
   printf '%s %s' "$1" "$2"
   shift
   shift
done

Last edited by NevemTeve; 07-21-2012 at 08:15 AM.
 
1 members found this post helpful.
Old 07-21-2012, 09:21 AM   #4
ofer4
Member
 
Registered: Apr 2012
Posts: 100

Original Poster
Rep: Reputation: Disabled
thanks both

Last edited by ofer4; 07-21-2012 at 05:02 PM.
 
Old 07-21-2012, 05:04 PM   #5
ofer4
Member
 
Registered: Apr 2012
Posts: 100

Original Poster
Rep: Reputation: Disabled
hi

i try to understand what is the difference between ' ' and " " in printf?

i tried to search about it, however i dont already got it..

can someone please explain me what is the difference between:

printf "I got %s in the exam" "$var1"


printf `I got %s in the exam` "$var1"

thanks alot
 
Old 07-21-2012, 11:24 PM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,456

Rep: Reputation: 445Reputation: 445Reputation: 445Reputation: 445Reputation: 445
Actually, it is three different things, read bash-manual...

Code:
echo "$PATH" -- value of variable $PATH is echoed
echo '$PATH' -- literal $PATH echoed
echo pwd=`pwd` -- the output of pwd program is included

Last edited by NevemTeve; 07-23-2012 at 03:31 AM. Reason: (code) and (/code) added
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Adding text to end of a particular line in bash dagummit Linux - General 7 11-30-2010 10:22 AM
bash write to end of each line threeonethree Programming 13 11-29-2010 09:20 AM
BASH Sort list by end of line to x position in each line? SilversleevesX Programming 14 08-19-2010 08:30 PM


All times are GMT -5. The time now is 04:28 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration