Solved

Getting Rid of whitespace in echo command

Posted on 2004-09-23
5
322 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
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 50 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

785 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