Re: bash script question
I just find out: #!/usr/local/bin/bash export IFS= cuc=$* mkdir cuc Thanks anyway! László From: Dánielisz László laszlo_daniel...@yahoo.com To: freebsd-questions@freebsd.org Sent: Tue, December 1, 2009 8:37:04 PM Subject: bash script question Hello, I'd like to ask how can I read a variable in the same line when I launch a script? For example ./script.sh directory_name, and I want the script to creat the directory called directory_name or whatever I input there. Thank you! László ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: bash script question
On Tue, 1 Dec 2009 11:48:43 -0800 (PST), Dánielisz László laszlo_daniel...@yahoo.com wrote: I just find out: #!/usr/local/bin/bash export IFS= cuc=$* mkdir cuc The $* variable will expand to all arguments given on the command line, e. g. $ ./myscript foo bar baz will result in mkdir foo bar baz and so create a directory named foo\ bar\ baz including the spaces. If you only want to access the first parameter, use $1, and for good form, check it before further processing. Your use of quotes to include the parameter is already good form. :-) -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ... ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: bash script question
Dánielisz László wrote: I just find out: #!/usr/local/bin/bash export IFS= cuc=$* mkdir cuc Thanks anyway! László From: Dánielisz László laszlo_daniel...@yahoo.com To: freebsd-questions@freebsd.org Sent: Tue, December 1, 2009 8:37:04 PM Subject: bash script question Hello, I'd like to ask how can I read a variable in the same line when I launch a script? For example ./script.sh directory_name, and I want the script to creat the directory called directory_name or whatever I input there. Thank you! László ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org Why are you using bash? To make a shell script as portable as possible, use /bin/sh. Bash is a third party shell, that isn't included in a base installation (you're not using bash as root's shell, are you?). By using /bin/sh, you make sure the script will run without having to install any ports. Try this instead (check the Special parameters section in the sh(1) man page to get the difference between $* and $@ and an explanation as to why I quote the $@). #!/bin/sh mkdir $@ Cheers, Rolf Nielsen ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: bash script question
On Tue, 01 Dec 2009 21:06:34 +0100, Rolf G Nielsen laz...@lazlarlyricon.com wrote: Why are you using bash? To make a shell script as portable as possible, use /bin/sh. Bash is a third party shell, that isn't included in a base installation (you're not using bash as root's shell, are you?). By using /bin/sh, you make sure the script will run without having to install any ports. That's a very good advice. Using sh is strongly recommended for maximal portability. Use sh if you're not requiring features that are bash-only. -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ... ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: bash script question
On Tue, Dec 01, 2009 at 10:42:10PM +0100, Polytropon wrote: On Tue, 01 Dec 2009 21:06:34 +0100, Rolf G Nielsen laz...@lazlarlyricon.com wrote: Why are you using bash? To make a shell script as portable as possible, use /bin/sh. Bash is a third party shell, that isn't included in a base installation (you're not using bash as root's shell, are you?). By using /bin/sh, you make sure the script will run without having to install any ports. That's a very good advice. Using sh is strongly recommended for maximal portability. Use sh if you're not requiring features that are bash-only. Hi guys, Here's a bash-related question, kind-of. Is there any way to automagically run my .csrhc thru a script and wind up with a bash script? gary -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ... ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org -- Gary Kline kl...@thought.org http://www.thought.org Public Service Unix http://jottings.thought.org http://transfinite.thought.org The 7.31a release of Jottings: http://jottings.thought.org/index.php ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: bash script question
Gary Kline wrote: On Tue, Dec 01, 2009 at 10:42:10PM +0100, Polytropon wrote: On Tue, 01 Dec 2009 21:06:34 +0100, Rolf G Nielsen laz...@lazlarlyricon.com wrote: Why are you using bash? To make a shell script as portable as possible, use /bin/sh. Bash is a third party shell, that isn't included in a base installation (you're not using bash as root's shell, are you?). By using /bin/sh, you make sure the script will run without having to install any ports. That's a very good advice. Using sh is strongly recommended for maximal portability. Use sh if you're not requiring features that are bash-only. Hi guys, Here's a bash-related question, kind-of. Is there any way to automagically run my .csrhc thru a script and wind up with a bash script? gary -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ... ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org If by Is there any way you mean is it possible, the answer would have to be yes. The next question is most likely has anyone written such a script? and to that question, someone else will have to provide the answer. Rolf Nielsen ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: bash script question
On Tue, 1 Dec 2009 13:45:55 -0800, Gary Kline kl...@thought.org wrote: Hi guys, Here's a bash-related question, kind-of. Is there any way to automagically run my .csrhc thru a script and wind up with a bash script? csh and (ba)sh use dufferent syntax and variable names. But you could write an easy search and replace translator for the .cshrc settings, which are mostly alias foo = 'bar' set var = value setenv envvar = value but for some of them, there's no bash equivalent (e. g. set promptchars and set promt in cshrc, but PS1 in bash). I'm not aware of an already existing mechanism that does this. Running one shell from the other doesn't transport most of the settings. -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ... ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: bash script question
On Tue, Dec 01, 2009 at 11:02:07PM +0100, Rolf G Nielsen wrote: Gary Kline wrote: On Tue, Dec 01, 2009 at 10:42:10PM +0100, Polytropon wrote: On Tue, 01 Dec 2009 21:06:34 +0100, Rolf G Nielsen laz...@lazlarlyricon.com wrote: Why are you using bash? To make a shell script as portable as possible, use /bin/sh. Bash is a third party shell, that isn't included in a base installation (you're not using bash as root's shell, are you?). By using /bin/sh, you make sure the script will run without having to install any ports. That's a very good advice. Using sh is strongly recommended for maximal portability. Use sh if you're not requiring features that are bash-only. Hi guys, Here's a bash-related question, kind-of. Is there any way to automagically run my .csrhc thru a script and wind up with a bash script? gary -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ... ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org If by Is there any way you mean is it possible, the answer would have to be yes. The next question is most likely has anyone written such a script? and to that question, someone else will have to provide the answer. Rolf Nielsen (sheepishly, and hanging my head) yes. does anybody have a csh/cshrc-alias to a bash/bashrc-alias script? i've got hundreds of aliases to be just deleted, i suppose, by dozens more. [ ] { please, sur, might i have more to eat? i'm hungry... { beg, contrition... .} } -- Gary Kline kl...@thought.org http://www.thought.org Public Service Unix http://jottings.thought.org http://transfinite.thought.org The 7.31a release of Jottings: http://jottings.thought.org/index.php ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: bash script question
On Tue, Dec 01, 2009 at 11:10:33PM +0100, Polytropon wrote: On Tue, 1 Dec 2009 13:45:55 -0800, Gary Kline kl...@thought.org wrote: Hi guys, Here's a bash-related question, kind-of. Is there any way to automagically run my .csrhc thru a script and wind up with a bash script? csh and (ba)sh use dufferent syntax and variable names. But you could write an easy search and replace translator for the .cshrc settings, which are mostly alias foo = 'bar' set var = value setenv envvar = value but for some of them, there's no bash equivalent (e. g. set promptchars and set promt in cshrc, but PS1 in bash). I'm not aware of an already existing mechanism that does this. Running one shell from the other doesn't transport most of the settings. Ah, Polyt to the rescue. I already have things like setenv aliased to ksh/zsh/borne-again/ and probably even /bin/sh || /bin/ash. I thought that especially bash was still persnikity. It used to be centuries ago, so I just stuck with zsh. Another deal was that I rarely use root, so it didn't worth it. But now, sweating the End of Days, yup. I'll see if vim can come to the resuce. thankee. gary -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ... -- Gary Kline kl...@thought.org http://www.thought.org Public Service Unix http://jottings.thought.org http://transfinite.thought.org The 7.31a release of Jottings: http://jottings.thought.org/index.php ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org