LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-09-2017, 02:42 AM   #1
utnubudnai
LQ Newbie
 
Registered: May 2008
Posts: 2

Rep: Reputation: 0
Question why set command change $1's value?


Code:
cat a.sh
Code:
#!/bin/bash
echo $*
set a=b
echo $*
Code:
bash a.sh 1 2 3 4 5
and the output is
1 2 3 4 5
a=b

why command
Code:
set a=b
change $1's value?

Last edited by utnubudnai; 01-09-2017 at 02:43 AM. Reason: bad composing
 
Old 01-09-2017, 02:56 AM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 4,407
Blog Entries: 6

Rep: Reputation: 2372Reputation: 2372Reputation: 2372Reputation: 2372Reputation: 2372Reputation: 2372Reputation: 2372Reputation: 2372Reputation: 2372Reputation: 2372Reputation: 2372
Because that is exactly what the set command is supposed to do. What were you expecting it to do?

See man bash, look under Shell Builtins, set for full details, but here is the applicable part:

Code:
set [+abefhkmnptuvxBCEHPT] [+o option-name] [arg ...]
       ...Any arguments remaining  after  option  processing  are treated as values for the positional parameters...
And welcome to LQ
 
1 members found this post helpful.
Old 01-19-2017, 10:14 AM   #3
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 729

Rep: Reputation: 75
Hi.

In the off-chance you have been coding/inherited csh, one does use:
Code:
set a=b
for assignments, but in Bourne shell relatives, one should use:
Code:
a=b
Compare man pages for csh/tcsh with man pages for sh/bash/ksh.

Best wishes ... cheers, makyo
 
1 members found this post helpful.
Old 06-06-2017, 07:55 AM   #4
utnubudnai
LQ Newbie
 
Registered: May 2008
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks astrogeek, and makyo, your replies are very useful for me, happy to know you guys
 
Old 06-06-2017, 08:26 AM   #5
BW-userx
Senior Member
 
Registered: Sep 2013
Location: MID-SOUTH USA
Distribution: Void Linux / Slackware 14.2
Posts: 4,628

Rep: Reputation: 857Reputation: 857Reputation: 857Reputation: 857Reputation: 857Reputation: 857Reputation: 857
look into 'shift' to move the value over to the next one.

The shift built-in

Handling positional parameters
excerpt
Code:
Shifting

The builtin command shift is used to change the positional parameter values:

    $1 will be discarded
    $2 will become $1
    $3 will become $2
    …
    in general: $N will become $N-1

Last edited by BW-userx; 06-06-2017 at 08:28 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Does bash script has equivalent set /p command as Windows shell command? ncheng Linux - Newbie 5 06-30-2016 05:29 AM
How to change screen set up through command-line on NVIDIA cards x_terminat_or_3 Linux - Hardware 2 05-21-2012 01:15 PM
PATH set incorrectly and lost bash: vi command... how can I change .bashrc? Lindz Linux - Newbie 10 09-23-2009 05:01 AM
how to change/set fqdn? johnpaulodonnell Linux - Newbie 1 04-27-2007 07:05 AM
change the background for X windows and set to fill whole screen and set screen saver eatranman Linux - Newbie 2 05-10-2006 08:41 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration