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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:20:53+00:00 2026-05-22T21:20:53+00:00

I have been looking on Google for quite a while now and can’t find

  • 0

I have been looking on Google for quite a while now and can’t find anything that is matching what I need/want to do.

My objective is to write a script that takes two arguments. It will search through the first argument (which is a list) and detect if the second argument is already in it. For example:

list = /bin/foo:/bin/random:random

to add to list: /bin/foobar

Calling the script will produce the result of /bin/foo:/bin/random:random:/bin/foobar.

If the part to add to the list is already in the list then nothing will be changed of the original.

I have everything working up until the point where I want to modify the parameter I passed.

...
if [ $RUN = 1 ]; then
    echo $1
else
    $1="$NEWLIST"
fi
exit 0

This however produced an error. It says that the command isn’t found and gives me the line number that $1=”$NEWLIST” is on. What am I doing wrong here? How do I modify $1? Thanks!

edit:

$ PATH=/opt/bin:$PATH
$ ./scrip.sh PATH /user/opt/bin
$ /opt/bin:/user/opt/bin

This is what I would want as a result of the script.

  • 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-22T21:20:54+00:00Added an answer on May 22, 2026 at 9:20 pm

    adymitruk already said it, but why do you want to assign to a parameter. Woudln’t this do the trick?

    if `echo :$1: | grep ":$2:" 1>/dev/null 2>&1`
    then
      echo $1
    else
      echo $1:$2
    fi
    

    Maybe this:

    list="1:2:3:4"
    list=`./script $list 5`;echo $list
    

    BIG EDIT:

    Use this script (called listadd for instance):

    if ! `echo :${!1}: | grep ":$2:" 1>/dev/null 2>&1`
    then
      export $1=${!1}:$2
    fi
    

    And source it from your shell. Result is the following (I hope this is what wsa intended):

    lorenzo@enzo:~$ list=1:2:3:4
    lorenzo@enzo:~$ source listadd list 3
    lorenzo@enzo:~$ echo $list
    1:2:3:4
    lorenzo@enzo:~$ source listadd list 5
    lorenzo@enzo:~$ echo $list
    1:2:3:4:5
    lorenzo@enzo:~$ list2=a:b:c
    lorenzo@enzo:~$ source listadd list2 a
    lorenzo@enzo:~$ echo $list2
    a:b:c
    lorenzo@enzo:~$ source listadd list2 d
    lorenzo@enzo:~$ echo $list2
    a:b:c:d
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey, I have been looking on google and I cannot seem to find anything
I have been looking through Google and SO for something that could help me
I have been looking all over google to find some answers to my questions
I have been looking for a 5-Star rating control for a while now and
I have been looking all around Bing and Google trying to find this, does
I have been looking around ocn Google and Stackoverflow but haven't found what I
I have been looking for a regular expression with Google for an hour or
Have been looking at the MVC storefront and see that IQueryable is returned from
I've been looking around Google and SO and haven't quite found an answer to
I have been looking at the YouTube Insight function and want to learn how

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.