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)
#!/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]"