[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Getting Rid of whitespace in echo command

Posted on 2004-09-23
5
Medium Priority
?
330 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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…
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.
Suggested Courses

656 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