Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3313586
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:07:57+00:00 2026-05-17T22:07:57+00:00

I have a question on the test command in the KornShell (ksh). I know

  • 0

I have a question on the test command in the KornShell (ksh). I know -ne is for comparing integers and != is for comparing strings. How will the test command behave if one argument is a string and the other is an integer? I have below conditions in my code and both are working properly.

Code:

myCount=1
myCount=`expr $myCount+ 0`
temp=`ps -aef | grep damn | wc -l`
if [ $temp -ne $myCount]; then
        echo ERROR Number
fi

if [ $temp != $myCount ]; then
        echo ERROR Strings
fi

Output:

ERROR Number
ERROR Strings
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:07:57+00:00Added an answer on May 17, 2026 at 10:07 pm

    The type is not relevant because it’s a simple text substitution. In other words, the value of the variable $temp will be substituted in place of $temp (for example).

    At least for the version of ksh I’m running, for the numeric comparison, if the value starts with a non-numeric, it will equate to 0. If it starts with a numeric but contains non-numerics, you will get an error.

    For example:

    $ export s1=xyz
    $ export s2=7xyz
    $ export i1=0
    $ if [ $i1 -eq $s1 ]
    > then
    >     echo equal
    > fi
    equal
    $ if [ $i1 -eq $s2 ]
    > then
    >     echo equal
    > fi
    ksh: 7xyz: bad number `7xyz'
    

    However, based on your comments, that may not be the case for all versions of ksh.

    Based on that, I would try to ensure that you use string comparisons for strings and numeric comparisons for numbers. Anything else may be non-portable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the test.ksh script my question if it possible to define in the
I have a simple unit test case (extensive question here ) on a configuration
Following on from this question...I'm trying to unit test the following scenario: I have
Another ggplot legend question! I have a dataset of the form test <- data.frame(
The Disclaimer First of all, I know this question (or close variations) have been
Similar to this question I have a small groovy test script that basically uses
i just have a simple question on the output of the shell command.The below
I have two Tables: Table 1: Questions : QuestionId NUMERIC Title TEXT Test Data
I've got 2 questions about organising Unit tests. Do I have to put test
I have question about parsing in Html helper : I have sth like: @foreach

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.