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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:01:56+00:00 2026-06-10T14:01:56+00:00

Are the following two boolean expressions the same? if [ -n $1 ] ;

  • 0

Are the following two boolean expressions the same?

if [ -n $1 ] ; then   
if [ -n "$1" ] ; then

And these two

if [ $? == 0 ] ; then
if [ "$?" == 0 ] ; then

If not – When should you put a variable in quotes?

  • 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-06-10T14:01:57+00:00Added an answer on June 10, 2026 at 2:01 pm

    put variables in quotes when there is any chance that the value may contain white spaces, or in general NOT be a continuous string of characters. So

    as $? should always be something between 0 and 255, you don’t need to quote that because it is a return value set after each sub-process returns. It is NOT possible to break that by assigning a string value directly, i.e.

    $?=Is of course wrong and should be
    
     ?=Bad value assigment
    

    because a user variable name must start with [A-Za-z_] , so don’t do that 😉

    Whereas for $1, if a value is passed in like

    myscript "arg1 with spaces"
    

    the test

    if [ -n $1 ] ; then
    

    will blow up,

    but the test

    if [ -n "$1" ] ; then  
    

    will succeed.

    IHTH

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

Sidebar

Related Questions

I have the following two tables: auth_user id username is_active (boolean) ... useprofile_userprofile id
I have the following two chunks of code, I am not so sure what
I was trying to lock a Boolean variable when I encountered the following error
The following two queries return the same (expected) result when I query my database:
The following two controls on my page: <asp:LinkButton ID=OpenLB runat=server >Open</asp:LinkButton> <asp:HyperLink ID=OpenHL runat=server>Open</asp:HyperLink>
The following two lines of code load an image from an SVG file and
The following two functions are extremely similar. They read from a [String] n elements,
I have the following two tables in my mysql database. Table Name: groups id
Consider the following two EXPLAINs: EXPLAIN SELECT * FROM sales WHERE title != 'The'
I have defined the following two functions test <- function(t) { return( (0.5*eta^2/theta)*(1-exp(-2*theta*t)) )

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.