Skip to main content
singular/plural has/have
Source Link

"$*" havehas few uses, the other answers cover why.

Here's a neat example of using "$*" to just "print everything" when doing error handling:

error () {
  printf '%s\n' "$*"
  exit 1
}

This script demonstrates the difference:

% cat foo.sh 
#!/usr/bin/env bash

error1 () {
  printf '%s\n' "$*"
  #exit 1
}

error2 () {
  printf '%s\n' "$@"
  #exit 1
}

error1 "aa" "bb"
echo "---"
error2 "aa" "bb"
% ./foo.sh  
aa bb
---
aa
bb

"$*" have few uses, the other answers cover why.

Here's a neat example of using "$*" to just "print everything" when doing error handling:

error () {
  printf '%s\n' "$*"
  exit 1
}

This script demonstrates the difference:

% cat foo.sh 
#!/usr/bin/env bash

error1 () {
  printf '%s\n' "$*"
  #exit 1
}

error2 () {
  printf '%s\n' "$@"
  #exit 1
}

error1 "aa" "bb"
echo "---"
error2 "aa" "bb"
% ./foo.sh  
aa bb
---
aa
bb

"$*" has few uses, the other answers cover why.

Here's a neat example of using "$*" to just "print everything" when doing error handling:

error () {
  printf '%s\n' "$*"
  exit 1
}

This script demonstrates the difference:

% cat foo.sh 
#!/usr/bin/env bash

error1 () {
  printf '%s\n' "$*"
  #exit 1
}

error2 () {
  printf '%s\n' "$@"
  #exit 1
}

error1 "aa" "bb"
echo "---"
error2 "aa" "bb"
% ./foo.sh  
aa bb
---
aa
bb
$* is not useful unquoted, minor readability fix to example, +1
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

$* or "$*" have few uses, the other answers cover why.

Here's a neat example of using "$*" to just "print everything" when doing error handling:

error () {
  printf '%s\n' "$*"
  exit 1
}

This script demonstrates the difference:

% cat foo.sh 
#!/usr/bin/env bash

error1 () {
  printf '%s\n' "$*"
  #exit 1
}

error2 () {
  printf '%s\n' "$@"
  #exit 1
}

error1 "aa" "bb"
echo "---"
error2 "aa" "bb"

% ./foo.sh  
aa bb
---
aa
bb
% cat foo.sh 
#!/usr/bin/env bash

error1 () {
  printf '%s\n' "$*"
  #exit 1
}

error2 () {
  printf '%s\n' "$@"
  #exit 1
}

error1 "aa" "bb"
echo "---"
error2 "aa" "bb"
% ./foo.sh  
aa bb
---
aa
bb

$* or "$*" have few uses, the other answers cover why.

Here's a neat example of using "$*" to just "print everything" when doing error handling:

error () {
  printf '%s\n' "$*"
  exit 1
}

This script demonstrates the difference:

% cat foo.sh 
#!/usr/bin/env bash

error1 () {
  printf '%s\n' "$*"
  #exit 1
}

error2 () {
  printf '%s\n' "$@"
  #exit 1
}

error1 "aa" "bb"
echo "---"
error2 "aa" "bb"

% ./foo.sh  
aa bb
---
aa
bb

"$*" have few uses, the other answers cover why.

Here's a neat example of using "$*" to just "print everything" when doing error handling:

error () {
  printf '%s\n' "$*"
  exit 1
}

This script demonstrates the difference:

% cat foo.sh 
#!/usr/bin/env bash

error1 () {
  printf '%s\n' "$*"
  #exit 1
}

error2 () {
  printf '%s\n' "$@"
  #exit 1
}

error1 "aa" "bb"
echo "---"
error2 "aa" "bb"
% ./foo.sh  
aa bb
---
aa
bb
shebang line
Source Link

$* or "$*" have few uses, the other answers cover why.

Here's a neat example of using "$*" to just "print everything" when doing error handling:

error () {
  printf '%s\n' "$*"
  exit 1
}

This script demonstrates the difference:

% cat foo.sh 
#!/usr/bin/env bash

error1 () {
  printf '%s\n' "$*"
  #exit 1
}

error2 () {
  printf '%s\n' "$@"
  #exit 1
}

error1 "aa" "bb"
echo "---"
error2 "aa" "bb"

% ./foo.sh  
aa bb
---
aa
bb

$* or "$*" have few uses, the other answers cover why.

Here's a neat example of using "$*" to just "print everything" when doing error handling:

error () {
  printf '%s\n' "$*"
  exit 1
}

This script demonstrates the difference:

% cat foo.sh 
error1 () {
  printf '%s\n' "$*"
  #exit 1
}

error2 () {
  printf '%s\n' "$@"
  #exit 1
}

error1 "aa" "bb"
echo "---"
error2 "aa" "bb"

% ./foo.sh  
aa bb
---
aa
bb

$* or "$*" have few uses, the other answers cover why.

Here's a neat example of using "$*" to just "print everything" when doing error handling:

error () {
  printf '%s\n' "$*"
  exit 1
}

This script demonstrates the difference:

% cat foo.sh 
#!/usr/bin/env bash

error1 () {
  printf '%s\n' "$*"
  #exit 1
}

error2 () {
  printf '%s\n' "$@"
  #exit 1
}

error1 "aa" "bb"
echo "---"
error2 "aa" "bb"

% ./foo.sh  
aa bb
---
aa
bb
Source Link
Loading