Shell Scripting Tutorial-22: Count The Number of Command Line Arguments Using $#

preview_player
Показать описание
In this tutorial you'll learn to find the number of positional parameters set either through the 'set' command or through the command line arguments, using system variable $#.
Рекомендации по теме
Комментарии
Автор

Thanks Madhur ..
Your Tutorials are awesome
Its 4:30 AM
Shows your Hard work

alterguy
Автор

I'm still hanging in, the lessons are really food for the baby coder's mind. Keep'em coming.

maimster
Автор

TOM HANKS IS MY FAVOURITE ACTOR TOO!!! BROFIST

Deeley
Автор

Wow Madhur, Thanks for such tutorial your concept expiation of shell script is this series very help full, Consisting i am watching and it is helping me allot to decrease the complexity of my script into, smooth one,

Thanks

AtulSharma-zxxv
Автор

to make things easier you can type in the terminal :
gedit ss7.sh
and press enter. It will automatically save your file in the working directory with '.sh' at the end.

bijoyandas
Автор

This script is for getting number of files and folders in pwd and user shouldn't need to pass any arguments. So, this should be done without requiring command line arguments.
set `ls`
echo $#
will do the work.

AtulShree
Автор

Hi when I am using this script the $# is taking the value of old set command

BanglaPlaylist
Автор

Yes, number of items in current directory is correct.

mokarem
Автор

what if I wanted to print a specific command line argument?

Hitori
Автор

Thanks for nice tutorials...but nowhere the set command is used...how is it setting the parameter and printing the count of files and dirs..in bash script also only $# is mentioned

theamitdost
Автор

sir. i have one doubt in linux shell scripting:

cat > prakash.sh
set `welcome to linux shell scripting this is my first shell script`
echo $#

i expect output is : 11, but it shows some junk files

and

if i give this input :
echo the total no of item in current directory to check this output is=$#

it's show output 8 why it show 8 only remaining 4 where

souravprakash
Автор

Why haven't you used " " in the statement of the echo command?

murifedontrun
Автор

Most probably it'll become clear further on, but by now I don't exactly get how this script works... All of the previous methods to set environment variables started from the beginning and overrode previous settings. How come now it counts them, without a loop, without declaring any variables to store previous attempts? I guess I need a deeper understanding of the shell, so... proceed with the tutorials. On a sidenote: thanks, awesome job.

katarzynajoanna
Автор

but when i run the command
echo $# after running the set command
i received the output 0..

geeteshmittal
Автор

Check out Udemy . You can be a tutor on Udemy as well.

davidmbonu
Автор

there are total 12 file in my home directory and its showing 20
:P

bhaskerthapa
welcome to shbcf.ru