Positional Arguments In Bash VS Posh (Powershell)

1. bash

all args with $*

  • $* is a special variable holding all of the passed arguments to the script via CLI
prnt(){
echo "you passed me" $*
}
>>> prnt fd fd dssddd fdfd
you passed me fd fd dssddd fdfd

one arg with $<n>

  • $1 is a special variable that denotes the first arg passed to the script via CLI
prnt(){
echo "you passed me" $1
}
>>> prnt fd fd dssddd fdfd
you passed me fd

2. posh

all args with $args

  • in PowerShell you don’t number the arguments passed, those go into $args array and you can iterate over them
Function search-google {
$query = 'https://www.google.com/search?q='
$args | % { $query = $query + "$_+" }
$url = $query.Substring(0, $query.Length - 1)
start "$url"
}
>>> search-google hello my friends

one $args[n]

function prr() {write-host $args[0]}
# prr rr tt ss
# >>> rr

3. links

--

--

--

Infrastructure Support Engineer/Technical Writer (Snowplow Analytics) with a passion for Python/writing documentation. More about me: https://pavol.kutaj.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Combining Data Sources: Transforming data for Performance & Clarity

5 Must-Try Web scraping tools

What is Cloud Computing

DEFIT | Dev Update April 2022

DEFIT Digital Fitness cryptocurrency update about move to earn and web3 development.

Ansible — An Automation tool

Statically typed languages vs Dynamically typed languages

How do i Start, Where do i begin, Is it the right thing, Do I even Know what am doing

Microservices, biology and evolution

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Pavol Kutaj

Pavol Kutaj

Infrastructure Support Engineer/Technical Writer (Snowplow Analytics) with a passion for Python/writing documentation. More about me: https://pavol.kutaj.com

More from Medium

General Bash Usage — 2 (Grep-Awk)

Java Development Kit(JDK) Installation and Deletion on Linux

The Linux Commands Series: Part VI

About Command Linux Shell