How to echo a set of variables with on a new line?
How to print set of variables in one line and next set in new line?
Example:
echo $uname $uid $fullname $homedirectory
开发者_JAVA百科
as
bob 1 bobby /sbin
max 2 maxwell /bin
I tried using \n at the end but it is giving new line for every variable like this
bob
1
bobby
/sbin
max
2
maxwell
/bin
But how to have \n at the end of set of variables?
Using echo
with -e
does what you are looking for
$ echo -e $HOME'\n'$HOME'\n'$HOME
/home/user
/home/user
/home/user
A simple man echo
is your friend
echo $uname $uid $fullname $homedirectory;echo
by just calling another echo w/o an argument, it will print a new line at the end of the previously printed line with the variables.
I don't see a reason you couldn't just use,
printf "$uname $uid $fullname $homedirectory\n"
instead, which is another member of coreutils. I know this doesn't fix the problem with echo, but it should give you the output you desire!
change #!/usr/sh
to #!/usr/bash
if you are running it inside a script.
You may Add this separator:
echo nl2br("\n");
<?php
$uname="bob";
$uid="1";
$fullname="bobby";
$homedirectory="/sbin";
echo $uname ." ". $uid ." ". $fullname ." ". $homedirectory;
echo nl2br("\n");
$uname="max";
$uid="2";
$fullname="maxwell";
$homedirectory="/bin";
echo $uname ." ". $uid ." ". $fullname ." ". $homedirectory;
?>
You can use simple echo command for this.
echo $uname."<br>".$uid."<br>".$fullname."<br>".$homedirectory."<br>";
精彩评论