#bash
31 December 2007
Total 15 pages. You are browsing page 1/15.
First :: Prev :: [1] [2] [3] [4] [5] [...] :: Next :: Last
--- Log opened Mon Dec 31 00:00:01 2007
00:54 <****> Is $IFS and for i in foo BASH specific?
00:58 <****> Ionic: no it's not
00:59 <****> So can I use it on every UNIX?
00:59 <****> Even those without BASH but POSIX sh compatible ones?
00:59 <****> it doesn't even have to be POSIX-compatible
00:59 <****> hm
01:00 <****> Ok... and...
01:00 <****> IFS and for i in foo have been around since the Bourne shell in the late 70s
01:00 <****> Do you think there is test with the option "-x" anywhere?
01:01 <****> test -x "$filename" or [ -x "$filename" ] is POSIX
01:01 <****> Alright, thank you :)
01:01 <****> test -x wasn't in ancient Bourne shell
01:03 <****> Mhh and is echo -e "\033[...m" also POSIX?
01:04 <****> no it's not
01:04 * foo tackles \amethyst
01:04 <****> So this is BASH specific?
01:04 <****> echo isn't very portable
01:04 <****> you can use printf
01:04 <****> printf "\033[...m\n"
01:04 <****> And this should work? :)
01:05 <****> On all platforms?
01:05 <****> well, I guess the problem with that is that printf is standard, but not necessarily portable to old systems
01:06 <****> Mh
01:06 <****> Ionic: what platforms are you targeting
01:06 <****> But those little things and octal ANSI escape strings should work, correct?
01:06 <****> \amethyst: well, as many as possible :)
01:06 <****> not necessarily in echo
01:06 <****> I meant printf
01:07 <****> if your environment has printf, they will work
01:07 <****> the risk is that /bin/sh will be so old as to not have printf
01:07 <****> Hmmm...
01:08 <****> So what's the deal?
01:08 <****> on SysV, echo takes no arguments, and always interprets backslash-escape sequences
01:08 <****> on BSD, echo doesn't interpret backslash-escapes, and it can take the argument -n
01:09 <****> s/argument/option/g
01:09 <****> Yeah, that's the problem :)
01:09 <****> printf is in the POSIX standard, but it was not in Bourne shell or in ksh '88 (which is a popular choice for /bin/sh on commercial Unices)
01:10 * HolidayMonk [Away] [Auto Away after 1666.65 minutes] [Left:01:09:58] [Pager:Off]
01:10 <****> Yeah
01:10 <****> almost every Unix around these days has a POSIX shell
01:10 <****> however, it's not necessarily the one in /bin/sh
01:10 <****> Hm well
01:10 <****> Can I test whether it is available or not?
01:20 <****> I mean checking for a program in $PATH is rather trivial, but since printf is supposed to be a built-in... is there any generic way?
01:23 <****> just use bash as your base imo
01:23 <****> it's pretty portable
01:24 <****> Not fully though :)
01:25 <****> yeah thing is i /hate/ posix sh. it always ends up with loads of set and eval's to emulate arrays without ever quite doing it (unless you're doing simple stuff)
01:26 <****> I've looked everywhere and for the life of me I can't figure out how to do arithmetic at the bash shell
01:26 <****> I am doing quite/very simple stuff without arrays or something like this :)
01:26 <****> Sweetandy
01:26 <****> Sweetandy: http://wooledge.org/mywiki/ArithmeticExpression
01:26 <****> Sweetandy
01:26 <****> Sweetandy: http://wooledge.org/mywiki/ArithmeticExpression
01:26 <****> bash arrays are portable to ksh93 anyway
01:26 <****> !y0
01:26 <****> m00, TheBonsai ;-)
01:26 <****> y0y0
01:26 <****> :P
01:26 <****> s/portable to/taken from/
01:26 <****> thx
01:27 <****> coprocesses would be nice though i must admit
01:27 <****> although ps is pretty hot
01:27 <****> So do you know hwo to check for a builtin? :)
01:28 <****> i don't in sh, only in bash
01:28 <****> type could do it
01:28 <****> except type isn't in ksh '88
01:28 <****> So uhm
01:29 <****> *sigh*
01:29 <****>
01:29 <****> THANKS!
01:29 <****> hehe
01:29 <****> And hash is portable? :)
01:30 <****> so don't you actually have a posix sh running to test?
01:30 <****> depends how you define portability
01:30 <****> hash is mentioned in SUS
01:30 <****> ah, 'type' is in ksh88
01:30 <****> it's a predefined alias
01:30 <****> good enough
01:30 <****> so you're fine
01:30 <****> Okay, I go for type
01:31 <****> do you want to check if a utility is *there* or if it's a *builtin*
01:32 <****> builtin
01:32 <****> ah
01:32 <****> erm
01:32 <****> why?
01:32 <****> printf won't be a builtin in old bash
01:32 <****> Well I could even check for "there"
01:32 <****> does the execution of your script fail if XY is not builtin but a file on disk?
01:33 <****> No, I build another for loop checking for that :)
01:34 <****> for what?
01:35 <****> A for-loop? :)
01:35 <****>&2; exit 1; }; done
01:35 <****> http://bash-hackers.org/wiki/doku.php/scripting/nonportable#check_for_a_command_in_path
01:36 <****> checking for what? gah nm
01:36 <****> that's how i usually do it, if the script depends on commands and i check for their availability
01:36 <****> *plunk*
01:37 <****> IFS=":"; for i in $PATH; do if [ -x "$i/printf" ]; then PRINTF=1; fi; done - igli :)
01:37 <****> that will ignore a builtin printf
Total 15 pages. You are browsing page 1/15.
First :: Prev :: [1] [2] [3] [4] [5] [...] :: Next :: Last
