LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-29-2019, 04:06 PM   #1
atharvdesai1996
LQ Newbie
 
Registered: Dec 2019
Posts: 13

Rep: Reputation: Disabled
Meaning of $0, $1 in shell


What is the meaning of $0, $1 etc in shell?

When I type $0 in ubuntu terminal, I get written as bash.
When I type $1 , $2etc and hit Enter, nothing appears on next line.

Please Explain
 
Old 12-29-2019, 04:12 PM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2147Reputation: 2147Reputation: 2147Reputation: 2147Reputation: 2147Reputation: 2147Reputation: 2147Reputation: 2147Reputation: 2147Reputation: 2147Reputation: 2147
Code:
#!/usr/bin/env bash

##enter four separate words on the command line then hit enter

echo $0 $1 $2 $3 $4
make that into a script, then run it.
./script .....

Last edited by BW-userx; 12-29-2019 at 04:14 PM.
 
2 members found this post helpful.
Old 12-29-2019, 04:32 PM   #3
atharvdesai1996
LQ Newbie
 
Registered: Dec 2019
Posts: 13

Original Poster
Rep: Reputation: Disabled
Smile Thanks alott!!

Quote:
Originally Posted by BW-userx View Post
Code:
#!/usr/bin/env bash

##enter four separate words on the command line then hit enter

echo $0 $1 $2 $3 $4
make that into a script, then run it.
./script .....
Thanks alot.
 
1 members found this post helpful.
Old 12-29-2019, 06:49 PM   #4
boughtonp
Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 821

Rep: Reputation: 604Reputation: 604Reputation: 604Reputation: 604Reputation: 604Reputation: 604
$1 and above are positional parameters which relate to a script's arguments - the Bash documentation for which is at https://www.gnu.org/software/bash/ma...nal-Parameters, and the POSIX specification is at https://pubs.opengroup.org/onlinepub...l#tag_18_05_01

$0 is a Special Parameter which expands to the name of the shell or script being run.
Another special parameter is $# which is the number of positional parameters.
 
Old 12-29-2019, 07:05 PM   #5
atharvdesai1996
LQ Newbie
 
Registered: Dec 2019
Posts: 13

Original Poster
Rep: Reputation: Disabled
Smile Thanks!!!!!

Quote:
Originally Posted by boughtonp View Post
$1 and above are positional parameters which relate to a script's arguments - the Bash documentation for which is at https://www.gnu.org/software/bash/ma...nal-Parameters, and the POSIX specification is at https://pubs.opengroup.org/onlinepub...l#tag_18_05_01

$0 is a Special Parameter which expands to the name of the shell or script being run.
Another special parameter is $# which is the number of positional parameters.
Thanks!!!
 
Old 12-29-2019, 09:44 PM   #6
wpeckham
Senior Member
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, Fedora, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, Vsido, tinycore, Q4OS
Posts: 3,503

Rep: Reputation: 1548Reputation: 1548Reputation: 1548Reputation: 1548Reputation: 1548Reputation: 1548Reputation: 1548Reputation: 1548Reputation: 1548Reputation: 1548Reputation: 1548
BTW: there is a lovely MAN page for BASH that should be installed on your system. I go back and read it about once a year, to rediscover useful things I might otherwise forget.
 
  


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
What is the meaning of $# in shell scripts? ravi_nandula Linux - Newbie 17 03-28-2012 07:00 AM
[SOLVED] what is the meaning $$ in shell procfs Linux - Newbie 3 01-14-2011 12:25 AM
meaning of if [ -z $SOMETHING....] in bash shell darwinianlo Linux - Newbie 8 08-09-2007 12:02 PM
"^" meaning in perl/shell script? fhleung Programming 8 01-03-2006 08:27 PM
'./file' meaning in python & shell script Chowroc Programming 7 12-30-2005 03:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:45 AM.

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
Open Source Consulting | Domain Registration