?
Solved

Getting Rid of whitespace in echo command

Posted on 2004-09-23
5
Medium Priority
?
328 Views
Last Modified: 2010-04-21
When I execute the below command, my result comes back with a bunch of spaces before the number, how do I get rid of the spaces?

Results:
$ ./ex7.ksh
There are        5 users on the system

Code:
#!/usr/bin/ksh

who | wc -l > count.dat
counter=`cat /Users/stoteve/regis/count.dat`


echo $counter
if [ $counter -gt 1 ]

then
            
echo "There are $counter users on the system"



elif [ $counter -eq 1 ]

then

echo "There are 1 users on the system"


elif [ $counter -eq 0 ]

then

echo "There are no users on the system"

fi
0
Comment
Question by:elwayisgod
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 11

Expert Comment

by:griessh
ID: 12136846
Hi elwayisgod,

Why don't you just use Tintin's comment in your question http://www.experts-exchange.com/Programming/Programming_Platforms/Unix_Programming/Q_21141569.html ?

======
Werner
0
 
LVL 11

Expert Comment

by:griessh
ID: 12136886
... you could even use mine ...
0
 
LVL 40

Expert Comment

by:jlevie
ID: 12136898
'who | wc -l | sed -e "s/ *//" >counter.dat' would work with your script as is. But it could be made more efficient by doing:

#!/bin/sh
#
counter=`who | wc -l | sed -e "s/ *//"`
case $counter in
  0)
    echo"There are no users on the system"
  ;;
  1)
    echo "There are 1 users on the system"
  ;;
  *)
    echo "There are $counter users on the system"
  ;;
esac
0
 
LVL 48

Accepted Solution

by:
Tintin earned 200 total points
ID: 12137987
The easiest way is to simply get rid of the quotes, ie:

echo There are $counter users on the system
0
 

Author Comment

by:elwayisgod
ID: 12138157
That is exactly what I was looking for. Not change my code but just get rid of whitespace in echo statement.  Thanks....

Sam
elwayisgod@hotmail.com
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses
Course of the Month14 days, 21 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question