![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Appending data into a variable | michaeltravisuk | Shell Programming and Scripting | 5 | 01-31-2009 04:20 AM |
| Appending to a variable? | paqman | Shell Programming and Scripting | 0 | 08-14-2007 01:16 PM |
| appending spaces to a variable | rallapalli | Shell Programming and Scripting | 2 | 08-13-2007 02:23 AM |
| Sed - Appending a line with a variable on it | eltinator | Shell Programming and Scripting | 4 | 07-30-2007 10:15 AM |
| appending space in binary data in c | arunkumar_mca | High Level Programming | 2 | 02-12-2007 09:30 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
appending space to variable
Hi
I need to write a script where there the user enters 3 input parameter variable number the program should ask the user left or right if it is left , the number specified that many spaces should be added to the value in front of the value and saved in the samee variable itself and if it is right that many number of spaces should be added in the right side for ex variable = vivek number =4 and when user echo $variable output should be if user opts for right then output = (4 spaces in front)vivek if user opts for left then output =vivek(4 spaces in back) |
|
||||
|
Code:
#!/bin/ksh
echo "Input variable: \c" ; read var
echo "Input number: \c" ; read pad
echo "Input Left or Right padding (L or R): \c" ; read lr
lr=$(echo $lr | tr '[a-z]' '[A-Z]')
if [ "$lr" != "R" ] && [ "$lr" != "L" ]
then
echo Invalid padding $lr !
exit
fi
while [ $pad != 0 ]
do
if [ "$lr" = "R" ]
then
var=$var" "
let pad=$pad-1
else
var=" "$var
let pad=$pad-1
fi
done
echo "[$var]"
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|