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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:47:36+00:00 2026-06-10T08:47:36+00:00

I am not quite sure how to understand this- $ var=’ ‘ $ echo

  • 0

I am not quite sure how to understand this-

$ var='  '
$ echo "|${var}|"
|  |
$ echo "|${var// /}|"
||

Vs.

$ set -- '' '' ''
$ echo "|${*}|"
|  |
$ echo "|${*// /}|"
|  |

However, when I add this after the above

$ IFS=
$echo "|${*// /}|"
||

What is going wrong in the second set of commands? Is this the expected outcome?

  • 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-10T08:47:38+00:00Added an answer on June 10, 2026 at 8:47 am

    Example 1

    $ var='  '
    $ echo "|${var}|"
    |  |
    $ echo "|${var// /}|"
    ||
    

    Here you have a simple string consisting of two spaces. When you expand it between two pipe characters, you see two spaces between the pipes. When you use pattern substitution to remove all the spaces from the expansion of the variable, you see the empty string between two pipes.

    Example 2

    $ set -- '' '' ''
    

    First, you’ve set each of the first three positional parameters to the empty string. You can observe this by comparing the results of the ${1-foo} with {$4-foo} (which displays the parameter if set, but ‘foo’ if it is unset).

    $ echo ${1-foo}
    
    $ echo ${4-foo}
    foo
    

    So we can see that $1 is set, but null, while $4 is unset.

    $ echo "|${*}|"
    |  |
    

    Next, we see the result of expanding the special parameter $* inside quotation marks, which is a single string consisting of the positional parameters that are set, separated by the first character of the IFS parameter. IFS by default has a space as its first parameter, so what we see is a string that consists of 3 empty strings, each separated by a space, which is just a single string of 2 spaces.

    $ echo "|${*// /}|"
    |  |
    

    When you apply pattern substitution to $*, the substitution is applied to each positional parameter separately before the resulting parameters are joined using IFS. Since the positional parameters are already empty, removing spaces from them leaves them unchanged. So you get the same result as when you just expanded $* by itself.

    Example 3

    $ IFS=
    $ echo "|${*// /}|"
    ||
    

    The procedure here is the same as in example 2, with the important difference that now IFS is the null string, rather than its default of ”. Once again, the pattern substitution doesn’t really do anything, because there are no spaces to remove from any of the positional parameters. But now, expanding $* results in a string consisting of the positional parameters with no intervening characters. Instead of $1 $2 $3, you get $1$2$3. Since all three are themselves empty strings, the result is the empty string.

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

Sidebar

Related Questions

To be honest I'm not quite sure if I understand the task myself :)
Not quite sure how to word this question. I am wondering if there is
I'm not quite sure the best way to deal with this situation. Here's a
I'm not quite sure how to go about styling this particular bit of php:
I'm not quite sure how to approach this issue: I am creating a web
I'm not quite sure I understand what Html.RenderAction() does. I've just noticed one weird
I am not quite sure I understand how to do the following. If I
I'm not quite sure about this in the standards. Say I have three files
I'm new to log4net and I'm not quite sure how to set up my
I've been reading through the Zend_View documentation, and I'm not quite sure I understand

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.