Solved

Getting Rid of whitespace in echo command

Posted on 2004-09-23
5
319 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
Comment Utility
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
Comment Utility
... you could even use mine ...
0
 
LVL 40

Expert Comment

by:jlevie
Comment Utility
'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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
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.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now