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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:20:44+00:00 2026-06-14T13:20:44+00:00

when I am working on shell script, I am little frusturate on $@ and

  • 0

when I am working on shell script, I am little frusturate on $@ and “$@” problem. So, I write a shell script to do some testing. like following.

func()
{
    local a="$@"
    for i in "$a";  do
        echo "$i ****"
    done
}

func000()
{
    local a="$@"
    for i in $a;  do
        echo "$i ****"
    done
}

func0()
{
    local a=$@
    for i in "$a";  do
            echo "$i ****"
    done
}

func00()
{
    local a=$@
    for i in $a;  do
        echo "$i ****"
    done
}

func1()
{
    for i in "$@";  do
        echo "$i ****"
    done
}

func2() 
{
    for i in $@;  do
        echo "$i ****"
    done
}

func "a b c"
func a b c 

echo "-----------"
func0 "a b c"
func0 a b c 

echo "-----------"
func00 "a b c"
func00 a b c 

echo "-----------"
func000 "a b c"
func000 a b c 

echo "-----------"
func1 "a b c"
func1 a b c 

echo "-----------"
func2 "a b c"
func2 a b c 




a b c ****
a b c ****   func
-----------
a b c ****   func0
a b c ****
-----------
a ****       func00
b ****
c ****
a ****
b ****
c ****
------------
a ****   func000
b ****
c ****
a ****
b ****
c ****

-----------
a b c ****     func1   //this has the result that I want. 
a **** 
b ****
c ****
----------- 
a ****      func2
b ****
c ****
a ****
b ****
c ****

As far as I remember, when using $@, we have to use double quoate, otherwise something will break. Therefore, I know some of functions definitely not work properly. (I still test it anyway)

Only func1 gives me a desire result, however, the thing is I want to assign “$@” to a variable. by reviewing func0, func000, func0, func00 results, none of those give me correct stuff. So, I am hoping someone can help me out.

In addition, I know sh and bash has difference. If someone can point me out in which condition something could break I will be so glad. Thanks.


update

I should say, this result of this script, it comes to the version of bash or sh, or freebsd sh vs linux sh.

I could be wrong, if so, just point it out, thanks a lot.

in old sh, freebsd sh, in which we do not have array, obviously, array assignment could not get working, the alternative is to use string like what I did in func000, local a=”$a”; for i in $a; do …

If using linux sh 4.5 (tested), or bash, see my answer below.

  • 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-14T13:20:46+00:00Added an answer on June 14, 2026 at 1:20 pm

    update, thanks to @jordanm, I realize this is the difference between bash and old sh version somehow.

    this is a solution in bash or sh 4.2. in old sh, this might not be working.

      33 func3()                                                                         
      34 {                                                                               
      35     local a=("${@}")                                                            
      36                                                                                 
      37     for i in "${a[@]}"; do                                                      
      38         echo "$i ****"                                                          
      39     done                                                                        
      40 }        
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

G'day, I'm getting syntax errors when working with a shell script like the following:
I have shell script like - while read -r line; do echo $line done
I am working on a Bash shell script that does something like this: #!/bin/bash
I'm working on a Bash shell script that runs several Python scripts like so:
I am currently working on a little backup script from some firebird databases and
I'm working with Ksh shell script, im doing following thing: for provide in $serviceProvideList
I was working on a little script that would do some logging for me
Yesterday I was working on a shell script to perform some moderately complex table
i am working on unix. i want to write a shell script which will
I'm working on a shell script to automate some server tasks. One the major

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.