| |
| |
| |
|
Page: 1 2 3 4 5 6
Comments:
<0> if FOO="blah (bar) blah" i would do FOO=${FOO//*(/}; echo ${FOO//)*/} <1> back... ok, what's the point? <2> not strictly bash but - is it possible to get xargs to run 2 commands for each match? <0> TheBonsai: simple way to get all (*) from string <0> best w/o the "(" ")" <0> just the * :] <1> supa_user: you may try to let xargs run bash -c 'your commands and use {}' or so <2> ah yes! <1> Peper: sed in that case ;) <1> Peper: it's the easiest IMHO. <2> TheBonsai: thanks, works! <1> supa_user: y0 <1> Peper: looks scary: <1> $ echo 'blah (bar) blah' | sed 's/^[^(]*(\([^)]*\)).*$/\1/' <1> bar <0> :D
<0> OMG ;] <1> (because () are control characters here, too) <3> supa_user: I believe you can pipe to while read ... in fact xargs might work with while read <0> output=$(sed 's/^[^(]*(\([^)]*\)).*$/\1/' <<< $input), ok? ;] <1> <<< "$input" <1> looks sane <0> ok <2> Vasistha: bash -c "{ cmd1; cmd2; }" works too <1> supa_user: why the {}? <0> TheBonsai: i have a function with http://rafb.net/paste/results/Zbjobf64.html to prevent it from doing the same many times <3> Peper: ...as long as you only have one level of parens <0> but it doesn't work <0> the CACHE var is always empty on the top of the func <1> you call it in a subshell <1> i suspect <3> Peper: I tend to use sed -r when doing fancy stuff like that, to get the extended regex support <0> TheBonsai: noo, other vars are kept <0> or amybe not ;] <1> Vasistha: especially that one wouldn't look much better with -r ;) <1> Peper: mh. weird. <2> TheBonsai: dunno, guess they're not needed if i spawn off bash <0> noo <0> you are right <0> i run it in $(..) <1> supa_user: put in there what you would write on prompt. <1> Peper: oh yea, there we go. <0> TheBonsai: any way to do the caching? ;] <1> Peper: oh wait. the variable isn't set INSIDE the function? <0> it is <1> ah, okay, then i was on the right way <0> so it's a global one <1> it's not changed afterwards you meant, yes? <1> (changed/set/whatever) <0> not <0> set just once <1> well, that's this $(subshell) yea <0> as in the paste <0> TheBonsai: any way to fix that? ;] <1> technically not. <1> you need another way <3> Peper: if your objective is to grab the word in parens, throwing out everything else, it works for me. You could also put double-quotes around the outside $( ) <4> hello <1> what exactly is that for? <4> how would i do something like $count++ in bash? <3> newby: (( count++ )) <1> to change only or to change and substitute, newby? <4> TheBonsai, change and substitute <4> like Vasistha said? <4> thanks <0> TheBonsai: it is in the process functions, which sets many vars <1> echo $((count++)) # newby. but i suspect you want ++count, anyways. <3> newby: if you want to use the value, prepend $ like TheBonsai said <0> and there are many small functions which call the process function with their $1 <1> Peper: then you need to change the way you do it. setting variables inside subshells is useless :) <3> newby: mine is only going to increment the variable, without giving it to you to work with <1> Peper: (if you want them after the subshell call, i mean) <4> TheBonsai, Vasistha thanks i dont want to echo it out, its perfect <4> thx <0> but the arg is very likely to be the same <1> newby: that's why i asked "change" or "change and substitute" ;) <0> if no arg specifed it defaults to some var
<1> newby: $(()) is for substitution, (()) is without <4> TheBonsai, i seeee, thanks! <1> Peper: it works when you call the fnction normal, because it will be operated in the actual shell. no problem here. <0> so no way to export a var from subshell to be available for another subshell <1> no way to let a variable survive. think of a process tree: no way to let the child change the memory contents of the parent <1> (exporting is the other direction, parent-->child) <1> if the subshell calls another subshell, aka parent-->chl1-->chl2, you have all in chl2, of course. but no way back. <1> inheritance is a one-way <0> i see <3> although of course you can "source" a script to import its variables <0> i have two bash scripts <0> let's say that the 1. is the one with func i am talking about <3> that's how e.g. .bashrc works ... you want to run the .bashrc process, and import the variable values (like $PS1) into your (parent) shell <0> it's sourced by the 2. but the funcs are executed in the subshell <0> so if i define a var in the 1. global scope <3> tias ;-) <3> ...may be easier to write a quick test first, instead of adapting your complex script <0> they will be then modified by the functions even run in subshell, right? <1> Vasistha: it's not about a plain variable definition, it's about a function call. if the function gets defined directly or by a source command makes no difference. it's the function call that runs in a subshell (in his special case) <3> Peper: I kinda don't think so :P <1> Peper: avoid the subshell. that's the only way :) <3> Peper: if you can have the function *return* the value you want? <0> i could do that <1> Peper: you simply try to do: <1> $ foo=baz; (foo=bar); echo $foo <1> baz <0> by the subshell way and func echoing is nice <0> TheBonsai: true ;] <5> how do I iterate through directories? <5> for i in $PATH ? <3> glen_quagmire: might be easiest with 'find' ... what are you trying to do? <5> let me formulate the question <1> glen_quagmire: by changing IFS <1> glen_quagmire: or by using for i in ${PATH//:/ } <5> i mean sub directories of /blah <1> oh <1> not the usual $PATH <1> heh <1> ok <3> glen_quagmire: yeah, you don't want/need $PATH at all <5> ok $path <0> ok, and if i change to the return way <5> $PATH is reserved <5> !faq <6> No matches found at http://wooledge.org/mywiki/BashFaq <7> glen_quagmire: faq - lookup BASH FAQ entries <7> glen_quagmire: usage: faq { number | regexp } <0> how are ***ignments made? <0> foo=func ? <1> $() <1> treat a function like an ordinary command on disk <5> i want to display all directories with full path under directory $dir <0> TheBonsai: i want to omit subshell <5> let's say $dir is /home/glen <8> find "$foo" -type d <5> yah <5> but that's space delimited..can i use it in for? <5> let me tias <1> Peper: no way :) <3> glen_quagmire: find "$dir" -type d | while read $subdir; do ...whatever you want... done <5> greycat: find has limit on the depth of recursion? <8> only if you tell it to. <5> ok man time <0> TheBonsai: so what's the difference between return and echo ? <5> -maxdepth 1 <0> other then that return stops execution of the func <1> Peper: a command has an exit code. so does a function. return sets that. a command has stdin/stdout/stderr. so does a function. echo uses the function's stdout <3> Peper: with echo, you can, e.g., foo=func(params) whereas with echo you need to do foo=$(func(params)) <5> but find also outputs $dir itself <3> Peper: heh, that should read, "with return, you can ... with echo, you need..." <0> Vasistha: TheBonsai just told me i can't <5> i watn list of 1st level subdirectories of $dir <8> Vasistha: syntax is wrong on the first one. <3> Peper: listen to him, he knows more than I do :P
Return to
#bash or Go to some related
logs:
#gentoo perl how to sort numberically vfs monitro
#ldap #linux python parse traceback #linux #math emerge KDEBASE problem with cyrus-sasl ioctl: LOOP_CLR_FD: Device or resource busy mount: you must specify the filesyst
|
|