Differences between revisions 1 and 3 (spanning 2 versions)
Revision 1 as of 2007-03-14 15:20:20
Size: 1528
Editor: GreyCat
Comment: First idiot catalogued.
Revision 3 as of 2007-03-30 15:28:52
Size: 5820
Editor: GreyCat
Comment: another one. similar pattern ("Oh, I didn't see your answer")
Deletions are marked like this. Additions are marked like this.
Line 4: Line 4:

{{{SpaceBass> hey folks, I have a backup script I'm working on... have a TEMPDIR var that has "/Vol/Disk 2/Backups" but for some reason then I use $TEMPDIR in my tar command its not escaping the space in the disk name (which I cannot change)
greycat> !quotes
greybot> USE MORE QUOTES! http://www.grymoire.com/Unix/Quote.html
ernstable> !quotes
greybot> USE MORE QUOTES! http://www.grymoire.com/Unix/Quote.html
ernstable> too slow
SpaceBass> I've tried using /Vol/Disk\ 2/Backups in the variable but that didnt help either
greycat> Try quotes.
SpaceBass> was the quotes comment directed at me?}}}
Line 31: Line 41:

{{{payal> How can I make a float into integer
payal> I have a number 5.6122211 - I want to compare it with a value in $var
greycat> !faq float
greybot> http://wooledge.org/mywiki/BashFaq#faq22 -- How can I calculate with floating point numbers instead of just integers?
payal> I have no bc and don't want to use awk - and I don't want a very precise answer
greycat> If you don't care about precision, just echo 0 every time.
payal> I have 5.6122211 in a variable $b and just want to know whether it is smaller or greate than $var - nothing much
greycat> !faq float
greybot> http://wooledge.org/mywiki/BashFaq#faq22 -- How can I calculate with floating point numbers instead of just integers?
payal> ((4.3 < 2.4)) && echo Success
payal> bash: ((: 4.3 < 2.4: syntax error in expression (error token is ".3 < 2.4")
greycat> !faq float
greybot> http://wooledge.org/mywiki/BashFaq#faq22 -- How can I calculate with floating point numbers instead of just integers?
payal> greycat: I already read that the first time - that is why I said I don
payal> t want to use bc or awk
greycat> *plonk* *plonk*
trash> payal: bash cannot handle float numbers. use external tools.
trash> !faq float
greybot> http://wooledge.org/mywiki/BashFaq#faq22 -- How can I calculate with floating point numbers instead of just integers?
trash> the 3rd time now.
greycat> trash: hence the *plonk*ing. She's the most stubborn person I've ever seen here.
trash> greycat: it's not the first time
redduck666> payal: if you are willing to settle for a simple string comparison you can use [[ $b > $var ]]
redduck666> payal: i said it is a string comparison :)
floyd_n_milan> !math
greybot> http://wooledge.org/mywiki/ArithmeticExpression
floyd_n_milan> payal, ^^ that?
greycat> floyd_n_milan: is she still asking about doing floating point comparisons?
floyd_n_milan> greycat, lol apparently
floyd_n_milan> payal, yeah, floating points not possible in bash
greycat> She's been given the FAQ entry at least 5 times now.
floyd_n_milan> mhmmm
redduck666> payal: there is no native way to do that in bash. you could break up the string in part before '.' and the part after '.' and than compare the two
floyd_n_milan> payal, are you interested in seriously learning bash
floyd_n_milan> payal, i don't doubt, i was just asking
floyd_n_milan> payal, read the O'Reilly book - Learning the bash shell, 3rd edition and then read man bash, practise and then check out the ABS guide on TLDP
floyd_n_milan> yeah it explains the basics nicely
floyd_n_milan> payal, meh give it a rest already
overrider_> payal, dude
floyd_n_milan> correction, dudette
overrider_> payal, you be either kicked or plonked}}}

{{{janson_> i have many files, named like '6540141.jpg 6540157.jpg 6540165.jpg' and i will check the two last digits (41,57,65) and move them into the dir with the same name. What will be the best commands to use for this?
janson_> i think the easiest is to use find and something more
janson_> mv ofc :D
janson_> but i will need to use regexp i suppose
greycat> for file in *.jpg; do x=${file%.jpg}; n=${x: -2}; echo mv "$file" $n; done
koala_man> !pe
greybot> Parameter Expansion. Expressions like ${foo%.mp3} and so on -- see man bash, and then search for Parameter Expansion. See also, http://wooledge.org/mywiki/BashFaq#faq74 and http://tiswww.tis.case.edu/~chet/bash/bashref.html#SEC30
 [... 14 minutes later ...]
janson_> find . -type f -name "*.jpg*" , now i need to cut out "51" in the file named "xyz51.jpg", how can i use parameter expansion for this?
greycat> janson_: my complete solution wasn't good enough for you?
janson_> greycat: ow, missed it. thanks}}}

You -- yes, you -- are an idiot!

Here are some other idiots in whose company you may find solace.

{{{SpaceBass> hey folks, I have a backup script I'm working on... have a TEMPDIR var that has "/Vol/Disk 2/Backups" but for some reason then I use $TEMPDIR in my tar command its not escaping the space in the disk name (which I cannot change) greycat> !quotes greybot> USE MORE QUOTES! http://www.grymoire.com/Unix/Quote.html ernstable> !quotes greybot> USE MORE QUOTES! http://www.grymoire.com/Unix/Quote.html ernstable> too slow SpaceBass> I've tried using /Vol/Disk\ 2/Backups in the variable but that didnt help either greycat> Try quotes. SpaceBass> was the quotes comment directed at me?}}}

{{{zald> how do i put \n for each line it output on this command " foovar=cat var; echo $foovar greycat> !pitfalls greybot> http://wooledge.org/mywiki/BashPitfalls greycat> !quotes greybot> USE MORE QUOTES! http://www.grymoire.com/Unix/Quote.html zald> payal, what is the proper way? zald> because the output is in online line greycat> zald: pitfalls. quotes. zald> status1=cat accesslist | grep -v -x $ipaddress1 ; greycat> specifically the pitfall whose content is echo $foo redduck666> !uuoc greybot> Useless Use of Cat (cat foo | grep bar). See <http://www.ruhr.de/home/smallo/award.html>. greycat> redduck666: you win that one :) redduck666> :) zald> what will i use then to replace cat greycat> Do you actually READ anything we tell you to read?! zald> sorry let me check greycat> hmm, actually the uuoc page assume the reader is not ignorant. zald> thank you so much payal, i just put an echo "$foo" , instead of echo $foo zald> thanks for the links greycat> My. Fucking. God. greycat> we told you THREE TIMES and then you thanked her.... floyd_n_milan> payal, meh give it a rest already floyd_n_milan> you guys should both just *plonk* each other you know greycat> at the moment, I'm just pissed off at that zald idiot for NOT reading the pitfalls page when I told him to (I even told him **which one to read**!) zald> im not aware that you are talking to me then greycat}}}

{{{payal> How can I make a float into integer payal> I have a number 5.6122211 - I want to compare it with a value in $var greycat> !faq float greybot> http://wooledge.org/mywiki/BashFaq#faq22 -- How can I calculate with floating point numbers instead of just integers? payal> I have no bc and don't want to use awk - and I don't want a very precise answer greycat> If you don't care about precision, just echo 0 every time. payal> I have 5.6122211 in a variable $b and just want to know whether it is smaller or greate than $var - nothing much greycat> !faq float greybot> http://wooledge.org/mywiki/BashFaq#faq22 -- How can I calculate with floating point numbers instead of just integers? payal> ((4.3 < 2.4)) && echo Success payal> bash: ((: 4.3 < 2.4: syntax error in expression (error token is ".3 < 2.4") greycat> !faq float greybot> http://wooledge.org/mywiki/BashFaq#faq22 -- How can I calculate with floating point numbers instead of just integers? payal> greycat: I already read that the first time - that is why I said I don payal> t want to use bc or awk greycat> *plonk* *plonk* trash> payal: bash cannot handle float numbers. use external tools. trash> !faq float greybot> http://wooledge.org/mywiki/BashFaq#faq22 -- How can I calculate with floating point numbers instead of just integers? trash> the 3rd time now. greycat> trash: hence the *plonk*ing. She's the most stubborn person I've ever seen here. trash> greycat: it's not the first time redduck666> payal: if you are willing to settle for a simple string comparison you can use $b > $var redduck666> payal: i said it is a string comparison :) floyd_n_milan> !math greybot> http://wooledge.org/mywiki/ArithmeticExpression floyd_n_milan> payal, that? greycat> floyd_n_milan: is she still asking about doing floating point comparisons? floyd_n_milan> greycat, lol apparently floyd_n_milan> payal, yeah, floating points not possible in bash greycat> She's been given the FAQ entry at least 5 times now. floyd_n_milan> mhmmm redduck666> payal: there is no native way to do that in bash. you could break up the string in part before '.' and the part after '.' and than compare the two floyd_n_milan> payal, are you interested in seriously learning bash floyd_n_milan> payal, i don't doubt, i was just asking floyd_n_milan> payal, read the O'Reilly book - Learning the bash shell, 3rd edition and then read man bash, practise and then check out the ABS guide on TLDP floyd_n_milan> yeah it explains the basics nicely floyd_n_milan> payal, meh give it a rest already overrider_> payal, dude floyd_n_milan> correction, dudette overrider_> payal, you be either kicked or plonked}}}

{{{janson_> i have many files, named like '6540141.jpg 6540157.jpg 6540165.jpg' and i will check the two last digits (41,57,65) and move them into the dir with the same name. What will be the best commands to use for this? janson_> i think the easiest is to use find and something more janson_> mv ofc :D janson_> but i will need to use regexp i suppose greycat> for file in *.jpg; do x=${file%.jpg}; n=${x: -2}; echo mv "$file" $n; done koala_man> !pe greybot> Parameter Expansion. Expressions like ${foo%.mp3} and so on -- see man bash, and then search for Parameter Expansion. See also, http://wooledge.org/mywiki/BashFaq#faq74 and http://tiswww.tis.case.edu/~chet/bash/bashref.html#SEC30

  • [... 14 minutes later ...]

janson_> find . -type f -name "*.jpg*" , now i need to cut out "51" in the file named "xyz51.jpg", how can i use parameter expansion for this? greycat> janson_: my complete solution wasn't good enough for you? janson_> greycat: ow, missed it. thanks}}}

Idiot (last edited 2021-11-05 15:08:05 by emanuele6)