Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Favorites infavorites:mine
infavorites:1234
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with Search options answers only user 52934

Questions on function usage in the context of Unix & Linux (mostly but not exclusively shell scripts). Questions on programming in Python, Perl, Ruby, etc. should be asked on Stack Overflow.

1
vote
While you're probably well set in a bash shell, to do similar portably you might employ something like the following... eval " for c in $(unalias -a for c do case ${c#function} in … ; done | tr '\t\n\0' ' \n' | sed -ne's/.* function .* / /p')"' ;do "$c"; printf %02s done' It works in stages: First weed out all args which contain any characters that …
answered Jul 21 '15 by mikeserv
0
votes
the same if its contents were the body of a script, or as is in the form of a shell function. _fn handles stdin - in this case "arg2" echoed over the |pipe - in the first line by setting its …
answered May 7 '14 by mikeserv
5
votes
not interested in reading that but still curious just understand that the here-docs attached to the function's input are evaluated for shell expansion before the function runs, and that they are … generated anew in the state they were when the function was defined every time the function is called. DECLARE You just need a function that declares other functions. _fn_init() { . /dev/fd/4 ; } 4 …
answered Apr 21 '14 by mikeserv
4
votes
sortnums(){ local OLDPWD IFS=' /' cd -- "$(mktemp -d)" || return touch -- $*; ls -A cd - >/dev/null && rm -rf -- "$OLDPWD" } Here's a slightly more complicated, and somewhat slo …
answered Dec 6 '15 by mikeserv
3
votes
Just use another function: fn(){ pass(){ shift "$shift" "$other" "$@" } other=fn2 shift=3 pass "$@" unset -f pass } It would be better, though, to iterate over the …
answered Feb 8 '15 by mikeserv
0
votes
I think probably the easiest answer here is to get the function out of those script files. #file[12] #foo() { : removed; } . ./foo.fn #and rest of script #foo.fn foo() { : old version is always …
answered Jan 15 '15 by mikeserv
0
votes
Well, you already know you get mail. That's pretty cool, because you definitely can execute a bash function when mail arrives. This is from man bash: $MAILPATH A colon-separated list of …
answered May 30 '15 by mikeserv
-1
votes
svcs network/shell | sed -n '/^online /c\ True' >> Solaris.txt ...should be pretty much the equivalent. The reason your script doesn't show anything, though, is that shell function is shell code … which must be executed by a shell which already knows it - the function must first be declared in the shell in which it is run in order to work. When you call xargs, however, you call a program which …
answered Jul 14 '15 by mikeserv
0
votes
execution environment. Any functions, variables, aliases or other kinds of shell state defined therein will persist when it returns. You can do an autoload sort of function definition, for example … , by defining a stub function: fn(){ . ./fn.file && fn "$@"; } ...where the file sourced contains a redefinition of fn(): fn(){ : a whole new fn } : any other init state commands you might like to run …
answered Dec 8 '15 by mikeserv
0
votes
You should do this w/ a forking logic of some kind. Set some marker in your script's environment which will definitely prove to child instances of your script that they should do one thing while the p …
answered Jul 8 '15 by mikeserv
2
votes
You're expecting: CONFIG_RESULT=$(configuer) To assign a value to $RECYCLEBIN because you... RECYCLEBIN="$value" ... in the configuer() function. It's true that the function does assign a value …
answered Jun 13 '14 by mikeserv
1
vote
Yes, and this becomes clearer when you consider what a shell function really is. For POSIX-compliant shells a function definition is standardized thus: 2.9.5 Function Definition Command A … function is a user-defined name that is used as a simple command to call a compound command with new positional parameters. A function is defined with a "function definition command"... as follows: fname …
answered Jan 18 '15 by mikeserv
1
vote
also prepends it with the string "$@". it sticks all of this in a function named for your second argument. here's an example: printf ' some_fn(){ echo some stuff cat </dev/null … ... another_fn printf %s\\n another_fn(){ for f in file*; do printf '%s\n' "$f"; done } i enclosed the function within one named for itself, and i can inspect it with printf or whatever, or i can …
answered Nov 13 '15 by mikeserv
7
votes
<<\HEREDOC_CMD_FILE #runs sh shell with heredoc input file { #begins current shell compound expression ( #begins subshell compound expression x() { echo 'I am function x … .' ; } #define function x x #x invoked in subshell ) #ends subshell compound expression x #x invoked in current shell } #ends current shell compound expression #v_end_v …
answered Jul 17 '14 by mikeserv
-1
votes
. Anyway, that is how that works. First it saves basically the entire body of the function, then, using that value, it defines a new cdtree() function which it can call from within the while loop for …
answered Jan 14 '16 by mikeserv

15 30 50 per page