• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

How to pass arguments in Bash Script on Debian 12

  • 00:33 cat /etc/os-release
  • 00:53 vim passargs
  • 02:41 chmod +x passargs
  • 02:50 ./passargs arg1 arg2 arg3 arg4
  • 03:59 vim passargs
  • 06:10 ./passargs test
  • 07:01 vim passargs
  • 08:23 ./passargs argument1 argument2 argument3 argument4
{{postValue.id}}

To Pass Arguments In Bash Script On Debian 12

Introduction :

Passing arguments in a Bash script allows you to provide input dynamically when running the script. Arguments are values passed to the script at the command line, enabling customization and flexibility.

Procedure :

Step 1: Check the OS version by using the below command.

root@linuxhelp:~/linuxhelp# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL=https://bugs.debian.org/

Step 2: Create and edit the file to make pass arguments script by using the below command.

root@linuxhelp:~/linuxhelp# vim passargs
#!/bin/bash

echo $0 $1 $2 $3 $4

echo $@

echo $#

Step 3: Make the executable permission to the script file by using the below command.

root@linuxhelp:~/linuxhelp# chmod +x passargs

Step 4: Run the script file with the arguments by using the below command.

root@linuxhelp:~/linuxhelp# ./passargs arg1 arg2 arg3 arg4
./passargs arg1 arg2 arg3 arg4
arg1 arg2 arg3 arg4
4

Step 5: Edit the file to use while loop with pass arguments by using the below command.

root@linuxhelp:~/linuxhelp# vim passargs
#!/bin/bash

#echo $0 $1 $2 $3 $4

#echo $@

#echo $#




while [ -f $1 ]
do
	echo "This script file $1 is exist"
done

Step 6: Run the script with arguments by using the below command.

root@linuxhelp:~/linuxhelp# ./passargs test
This script file test is exist
This script file test is exist
This script file test is exist
This script file test is exist
This script file test is exist
This script file test is exist

Step 7: Edit the file to use for loop with pass arguments by using the below command.

root@linuxhelp:~/linuxhelp# vim passargs
#!/bin/bash

#echo $0 $1 $2 $3 $4

#echo $@

#echo $#




#while [ -f $1 ]
#do
#	echo "This script file $1 is exist"
#done



for args in $@
do
	echo "This is Arguments: $args"
done

Step 8: Run the script with arguments by using the below command.

root@linuxhelp:~/linuxhelp# ./passargs argument1 argument2 argument3 argument4
This is Arguments: argument1
This is Arguments: argument2
This is Arguments: argument3
This is Arguments: argument4

Conclusion:

We have reached the end of this article. In this guide, we have walked you through the steps required to pass arguments in Bash Script on Debian 12. Your feedback is much welcome.

Tags:
jacob
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

How do I pass arguments to a Bash script on Debian 12?

A

To pass arguments in a Bash script, you can use the special variables `$1`, `$2`, .., `$n`, where `$1` represents the first argument, `$2` the second, and so on. Here's a quick guide.

Q

How many arguments can I pass to a Bash script?

A

You can pass as many arguments as needed. The variables `$1`, `$2`, etc., will represent the first, second, and so on, up to the total number of arguments.

Q

Can I use descriptive names for my arguments instead of `$1`, `$2`, etc.?

A

While the special variables are commonly used, you can also use named parameters by assigning values to variables within your script. For example, `first_arg=$1` allows you to use `$first_arg` in your script.

Q

How do I check if a specific argument is provided?

A

You can use conditional statements like `if [ -z "$1" ]` to check if the first argument is empty. Adjust the condition based on your specific requirements.

Q

Can I pass flags or options to my script?

A

Yes, you can use flags like `-h` or `--help`. To process them, you can use tools like `getopts` or simply check the values of `$1`, `$2`, etc., within your script.

Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Ganesh Konka ?
Zentya 6.1 http proxy configuration

please send link for creating zentyal 6.1 for http proxy and firewall as gateway.

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.