Solved

Getting Rid of whitespace in echo command

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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.
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.

724 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