Languages
[Edit]
EN

Bash - omit first argument from command line

3 points
Created by:
Maryamcc
541

In this article, we would like to show you how to omit first argument from command line in Bash.

Practical example

In this example, we use "${@:2}" to capture all arguments passed from command line starting from the second argument. Then we iterate through all parameters using for loop and print them using echo command.

Example script.sh file:

#!/bin/bash

for argument in "${@:2}"
do
    echo "$argument"
done

Run in the command line:

./script.sh one two three

Output:

two
three

 

See also

  1. Bash - capture all arguments passed from command line (regardless of their number)

Alternative titles

  1. Bash - skip the first argument from command line
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join