Changes
Jump to navigation
Jump to search
← Older edit
Newer edit →
$1
(view source)
Revision as of 07:59, 30 January 2020
375 bytes added
,
07:59, 30 January 2020
→$1 in bash functions
Line 30:
Line 30:
In bash functions, $1 server as the first bash function parameter and so on.
In bash functions, $1 server as the first bash function parameter and so on.
===Example===
===Example===
+
<syntaxhighlight lang="bash" >
+
#!/bin/bash
+
die(){
+
local m="$1" # the first arg
+
local e=$2 # the second arg
+
echo "$m"
+
exit $e
+
}
+
# if not enough args displayed, display an error and die
+
[ $# -eq 0 ] && die "Usage: $0 filename" 1
+
+
# Rest of script goes here
+
echo "We can start working the script..."
+
</syntaxhighlight>
Another example:
Another example:
−
+
<syntaxhighlight lang="bash" >
fingerprints() {
fingerprints() {
local file="$1"
local file="$1"
Line 39:
Line 53:
done < $file
done < $file
}
}
+
</syntaxhighlight>
Admin
Bureaucrats
,
Administrators
3,305
edits
Navigation menu
Personal tools
Log in
Namespaces
Page
Discussion
Variants
Views
Read
View source
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
Special pages
Printable version