Ok, I've got a basic bash scripting question, but the answer is so simple it eludes me. From my .bash_aliases file.... PROBLEM 1:
What variable(s) do I use for the hostname (or IP) and the username? I want to: $ reboot-win-host hostname-here username-here or $ reboot-win-ip ip-here username-here PROBLEM 2 For these, I can't get them to work for whatever reasoning....
asked 29 Dec '10, 22:43 Ron ♦ |
Problem 1. Don't use an alias, use a function:
Problem 2. Quotes do not nest. In Bash, within a single-quoted string, single-double-single-double-single produces a single quote mark:
This is because quoted strings are concatenated directly:
Different types of quotes do nest, but escapes and variable references within double-quotes are evaluated immediately. Fortunately, you can always escape escapes and variable references, too:
Therefore, your aliases should be written as, for example,
Note that I only tested these quickly; you probably should go thorough them to make sure. In the install-date alias, it's better to use find so that it works even with another locale; adjust the printf patterns to your liking (but keep the sort key, %TY%Tm%Td or YYYYmmdd intact). answered 31 Dec '10, 19:35 Nominal Animal Thanks man, that all works. I've yet to try the Windows rebooting code as of yet. I'll try that and if it works like the rest did, I'll mark the question answered. Thanks for all of the great help. I did +1 it already.
(03 Jan '11, 20:39)
Ron ♦
|
You already got your answer. If you want to pass command-line arguments to a script, they are called $1, $2, $3, etc. I like the discussion of functions. You could also just use separate scripts. Because $1, $2, etc are not very readable names, I might rewrite your script as follows.
answered 29 Jan '11, 04:45 pcardout |