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 7093739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:28:37+00:00 2026-05-28T08:28:37+00:00

In the following very simple ksh script example, I need to ask if func1

  • 0

In the following very simple ksh script example, I need to ask if func1 results equal to 4 ,

This is what I did in the example but this script does not print the “function result = 4” as I expected it to.

What do I need to change in the [[……]] in order to print the “function result = 4”

Remark – func1 must be in the [[…..]]

  #!/bin/ksh

  func1()
  {
    return 4
  }

  [[ ` func1 ` = ` echo $? `  ]]  && print "function result = 4"  
  • 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-28T08:28:38+00:00Added an answer on May 28, 2026 at 8:28 am

    You need

    #!/bin/ksh
    
      func1()
      {
        print -- 4
      }
    
      [[ $(func1) = 4  ]]  && print "function result = 4"  
    

    OR

    #!/bin/ksh
    
      func1()
      {
        return 4
      }
    
      func1 ; [[ $? == 4 ]]  && print "function result = 4"
    

    There are several issues in the code that you present, so let me try to explain (You’re making it more complicated than it need be).

    No. 1 is your use of back-ticks for command substitution, these have been deprecated in the ksh language since ~ 1995! Use $( … cmd ) for modern cmd-substitution. We often see backticks listed as a nod to portability, but only scripts written for systems where the Bourne shell is the only shell available require the use of backticks. (well, I don’t know about dash or ash, so maybe those too).

    No 2. is that $? gets set after ever function or command or pipeline is executed and is the return code of that last command. It is a value between 0-255. When you have code like cmd ; rc=$? ; echo $? ; you’re now echoing the status of the assignment of rc=$? (which will almost always be 0), AND that is why you will see experienced scriptors save the value of $? before doing anything else with it.

    Recall that command-substitution uses what ever is the output of the $( ... cmd ...) or backtics enclosed command while return sets the value of $? (until the very next command execution resets that value).

    I hope this helps.

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

Sidebar

Related Questions

the following code is very simple, but for some reason, for-loop does not iterate
I have the following very simple Javascript-compatible regular expression: <script type=text/javascript id=(.+) src=([^]+)> I
I am trying to make a very simple web-service which does the following: The
I'm programming a very simple socket server following this sample code . The server
This is very simple but I can't find a function to format string to
The following Java code is a very simple piece of code, but what are
I have the following issue whith this very simple task. I want to create
I have the following very simple Ext JS 4 script which is supposed to
I have the following piece of code for a very simple PHP polling script
I have a very simple makefile, that basically does the following: # Pre-compiled header

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.