On Fri, Oct 31, 2003 at 09:27:27PM +0100, [EMAIL PROTECTED] wrote: > Quoting Bijan Soleymani <[EMAIL PROTECTED]>: > > > On Fri, Oct 31, 2003 at 02:50:17PM -0500, Vivek Kumar wrote: > > > Hi, > > > > > > Is there any other command to print any character say "*" 80 times.. > > > > > > like echo "******************************" > > > (In bsh or ksh) > > > > > > Is there any short command ?? > > > > A possible not good way to do this in bash: > > for x in `seq 80`; do echo -n "*"; done ; echo > > > > the last echo is to get the newline to print. > > > > In perl you could do: > > perl -e 'for(1..80){print "*";}print "\n";' > > > > Technically that is shorter than: > > echo > > "********************************************************************************" > > Can you just explain how to use this for ? It seems far away the ones I know > (C,C++,basic,Java,php,etc.)
Since bash is the default shell in Debian you should be able to open up an xterm and type: for x in `seq 80`; do echo -n \*; done; echo Basically this is the bash (or sh) for loop. for variable in list; do list of tasks; done it takes the list of variables and then runs the list of tasks substituting into the variable each time. For example: [EMAIL PROTECTED]:~$ for x in 1 2 3; do echo $x; done 1 2 3 The command "seq n" generates a list of numbers from 1 to n. Enclosing it in parenthese makes the shell substitute it in the command line. My perl example was pretty bad: perl -e 'for(1..80){print "*";}print "\n";' The actual code is: for(1..80) {print "*";} print "\n"; 1..80 creates a list of numbers from 1 to 80 for in perl can be used both as in C/C++ or as in bash to loop over each element of a list. A better way of doing it in perl was described by David Z Maze: print "*" x 80 . "\n"; This prints the string "*" 80 times and sticks "\n" at the end. x in perl can be used to multiply a string. . in perl can be used to concatenate two string. Bijan -- Bijan Soleymani <[EMAIL PROTECTED]> http://www.crasseux.com
signature.asc
Description: Digital signature