| |
| |
| |
|
Page: 1 2 3 4 5 6 7
Comments:
<ddelony> Hello, world! <Aeiri> did you echo that? <ddelony> Yes :-) <Aeiri> YAY LETS PARTY <ddelony> I'm trying to write a script that prints everything in my PATH. <goldfish> he did not echo that! <goldfish> ddelony: "prints everything" ? <ddelony> I want ls all the directories in my PATH in one fell swoop. <ddelony> I want TO ls. <goldfish> for i in ${PATH//:/ }; do ls "$i"; done <ddelony> Let my fire up my editor to see if it works <goldfish> It's output isn't very "nice" <ddelony> In the string operator, I tried putting a newline character instead of a blank space. It just replaced the colon with an "n" <ddelony> How does that work? <goldfish> ...? <goldfish> What string operator? <ddelony> The ${PATH//:/ } <ddelony> I guess I should rtfmp. ;-) <goldfish> Hmmm. <ddelony> It's amazing than you can move mountains in a line of shell script. <goldfish> :) <ddelony> oops s/than/that <ddelony> I didn't set out to program but you can't fart in Unix without programming! <goldfish> shell script != programming <ddelony> How so? <goldfish> It's scripting. <goldfish> :) <ddelony> You're giving instructions for a computer to follow. Smells like programming to me! <goldfish> You're giving instructions for a shell to follow. <goldfish> Anyway, call it what you want. <ddelony> (Sigh), of such things Holy Wars are made. :-) <ddelony> Anyway, how 'bout that emacs! ;-) <goldfish> Never used it. <goldfish> I hear it's an operating system, though. <ddelony> It's a LISP environment with a text editor inside it. <heiner> goldfish: I would not agree with scripting not being programming. Programs can be interpreted or compiled, but both are still programs <goldfish> hehe :) <goldfish> Ok so. <goldfish> I stand corrected. <heiner> I wouldn't have done so, but I think that most of what we programmer learn for other languages (e.g. "C", "Java", ...) is true for shell script programming, too. <ddelony> I modified the script. I put the -x switch on the ls command so the output is neater. <goldfish> heiner: Good point. <SiegeX> two questions, 1) how do i get the length of an input parameter to a custom function? 2) Remind me how I evalute a variable that *must* be enclosed within single ticks. ie hexdump -e '$num/1 "x%02x"' <goldfish> ddelony: cool. <SiegeX> i want $num to be evaluated <SiegeX> and consequently i want $num to be the lenght of the parameter p***ed into the function <goldfish> lmello_at_home: are you there? <goldfish> :) <ddelony> Watchtower! <goldfish> SiegeX: ${#var} , is the length of the variable var <goldfish> as for forcing evaluation, i suppose you could use eval <goldfish> but there is... <goldfish> !faq eval <greybot> http://wooledge.org/mywiki/BashFaq#faq48 -- Why should I never use eval? <SiegeX> ya ive been trying ot figure out how to sneek that in <SiegeX> doesnt seem to want to work <goldfish> hmm. <SiegeX> unless you guys know a better way to urlencode <ddelony> I kinda skimmed that part in the O'Reilly book. <SiegeX> but then again, i havnt touched bash like this in quite some time <SiegeX> so im rusty <SiegeX> ooc, how would you implement eval in this situation? <heiner> SiegeX: There is an example of an urlencode script: http://www.shelldorado.com/scripts/cmds/urlencode <SiegeX> holy cow, heh thats alot longer than i thought. the only thing i want to do is turn ABC into %41%42%43 for example. <SiegeX> is that everything that script does? <heiner> SiegeX: yes, but it tries to do it in a safe way <heiner> SiegeX: well, the core code is just the small AWK program <SiegeX> i was thinking something along the lines of... <SiegeX> function urlencode { echo "${1}" | hexdump -e '${#1}/1 "%%%02%%"'; }; <SiegeX> cept it wont eval ${#1} in that <SiegeX> and it appears it doesnt like %% for a literal % so i might have to pipe it to sed <heiner> ...and "hexdump" is no standard function <SiegeX> true that but this is going to go into my .profile <SiegeX> also, this is a good refresher course for me. <SiegeX> function urlencode { hex=$(echo "${1}" | hexdump -e '1/1 "x%02x"' | sed 's/x/%/g ; s/%0a//'); echo http://www.example.com/twins.php?text=${hex}; }; <SiegeX> ok, so besides me using non standard functions, is that pretty clean? <SiegeX> for some reason 1/1 works and i dont need the length <SiegeX> so that cleared up the eval issue <TheBonsai> y0 <heng> hi, how to set delimiter to either one space or . when awking a line contains space and dot at the same time ? <heng> I tried it like : awk -F'[ \.]' '{print $1","$5}' , however it seems didnt work on the space <Aeiri> cant remember delims in awk, but you could use a regexp in sed to do the same thing <heng> Aeiri:thanks, I remember someone here mentioned this before, surely regexp can help, but I am curious how it worked before ? :-) <Aeiri> heng: ahh so you want to use awk? :P <heng> yes :-p <goldfish> [%] echo "a b.c d" | awk -F '[ .]' '{print $1,$2,$3,$4}' <goldfish> a b c d <SiegeX> heiner: maybe im just being lame but doesnt your script have to start with #!/bin/bash or some such? all I see is ":" which is if i remember the do-nothing command <heng> goldfish: thanks, let me double check why mine didnt work <goldfish> it should have. <Vasistha> SiegeX: I believe bash will run a script if asked, even if it doesn't start with that line <Vasistha> SiegeX: of course, implementations may vary <SiegeX> it should if you prefix it with 'bash' or 'sh' cept the way it states its usage it doesnt appear that he wants that to be the case <heiner> SiegeX: I do that deliberately, see the following discussion if you are interested why: http://groups.google.de/group/comp.unix.shell/browse_frm/thread/3c3a398af9e1f774/996226792663635a <SiegeX> ohh, it appears i misread how it works, it wants a file as input <heiner> SiegeX: in a nutshell: a ":" ensures that a script is run by a Bourne-compatible shell, which could be /bin/sh, but also BASH or ksh or ksh93 <Aeiri> doesnt every unix have a bourne-compatible shell at least linked to /bin/sh? <Aeiri> well, every unix that has a bourne shell, that i <Aeiri> s <SiegeX> good to know, never knew that <heiner> Aeiri: yes, but if you e.g. have a BASH as your login shell, and a script starts with ":", bash will run it (not /bin/sh). This can be a speed advantage. It definitely is a speed advantage if you have KornShell/ksh93 as your login shell, which is much faster than e.g. /bin/sh or bash <Aeiri> ah, huh <Aeiri> so like #!: or JUST :? <SiegeX> heiner: for some reason its just parroting out what i put in <heiner> Aeiri: just ":" <heiner> SiegeX: the "urlencode" script? <SiegeX> ya <heiner> SiegeX: it only "urlencodes" when necessary. Try to put whitespace or '*' or other special characters in <heiner> SiegeX: this makes for more readable URLs <SiegeX> oh so it wont convert the actual letters to hex? <heiner> SiegeX: only if necessary <SiegeX> oh wells <Aeiri> you dont need to convert actual letters to hex for URL encoding <SiegeX> i want something that will obfuscate the hell out of a URL <Aeiri> SiegeX: then use decimal IPs and stuff <Aeiri> dnsstuff.com has an example <Aeiri> for instance... 1089059683 is google.com <SiegeX> ya, im actually more interested in screwing with the text im p***ing in the URL, but thats an interesting idea too <SiegeX> doesnt appear firefox likes decimal ip's <Aeiri> works fine here <SiegeX> although i know IE did at one point cause i used to play with this awhile back <SiegeX> http://1089059683 ? <SiegeX> maybe its squid then <Aeiri> yeah <Aeiri> i doubt squid will support decimal ips <Aeiri> although firefox may convert it before sending the ip out <heiner> Aeiri: the IP address is never sent out, just used <Aeiri> uhh.... what is the TCP/IP stack for 500 trebek? <cconlin> Anyone know of a good starter tutorial for writing shell scripts? <Aeiri> http://www.tldp.org/LDP/abs/html/ <heiner> cconlin: Aeiri pointed you to a very comprehensive one. That one, and many others (often shorter) are listed here: http://www.shelldorado.com/links/ <cconlin> Thanks so much <heiner> beware: I'm not completely objective <cconlin> I started writing an 'init.d' script and it works, but I'm really interested in elaborating on it <DingoK> for all you bash people out there...help a new guy out. I want to invoke 'wc -l' recursively on a directory to count all the lines in all the files of the current directory and subdirectories. How would i do this ? <Aeiri> grep -r "" * | wc -l <goldfish> find . -type f -exec cat {} \; | wc -l <Vasistha> DingoK: how many subdirectories deep do you want to go? forever? <heiner> find . -type f -exec wc -l {} + <heiner> DingoK: are you also interested in the size (in KB or MB)? <Vasistha> does bash have some kind of built-in function to get hex values for characters? hexdump is a pita <Aeiri> od <Aeiri> echo -n "$char" | od -x | cut -d ' ' -f2 | sed "s/^..//g" <Aeiri> thats probably the most inefficient way to do it though <Aeiri> i have no idea :) <DingoK> sorry, leak in my ceiling <DingoK> i am not interested in size, only in the line count <DingoK> Vasistha: yes, forever <Aeiri> grep -r "" * | wc -l
Return to
#bash or Go to some related
logs:
deltaiso howto #kde forums.gentoo.org CONFIG_BLK_DEV_LOOP iso #bash CGI::scrolling_list #linux mainactor ubuntu dapper #linux #sdl #gentoo
|
|