GeoA Posted October 26, 2007 Share Posted October 26, 2007 I need help converting a small portion of a bash script--shown below. function doSomething () { for i in $@ do case $i in blah) do something ;; foo) do something else ;; bar) WTF, just do something ;; *) don't know what $i is so do something else ;; esac done } The problem I have is converting the "for i in $@" part becuase AutoIT doesn't seem to have the $@ variable for me to take advantage of. Any help would be appreciated greatly. Thanks G Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 26, 2007 Moderators Share Posted October 26, 2007 What is $@ supposed to be? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Fossil Rock Posted October 26, 2007 Share Posted October 26, 2007 Do you honestly expect someone to learn bash script (whatever that it) and then recode it for AutoIt ? Agreement is not necessary - thinking for one's self is! Link to comment Share on other sites More sharing options...
weaponx Posted October 26, 2007 Share Posted October 26, 2007 Bash script is a linux scripting language. The syntax presented here looks pretty simple. Why don't you post the actual script instead of a hacked up version with comments. Link to comment Share on other sites More sharing options...
Nevin Posted October 26, 2007 Share Posted October 26, 2007 Well, he said he just needs the $@ equivalent anyway. I know SOME bash, but never learned that. For those who don't know any bash at all, that's a case structure inside of a for loop.Bash Reference Manual:3.4.2 Special Parameters@ - Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, each parameter expands to a separate word. That is, "$@" is equivalent to "$1" "$2" .... When there are no positional parameters, "$@" and $@ expand to nothing (i.e., they are removed).Uhhm. I don't know what that means, so good luck Link to comment Share on other sites More sharing options...
MHz Posted October 26, 2007 Share Posted October 26, 2007 It is a code structure to test incoming Command Line Parameters. Check the AutoIt Help file index for Command Line Parameters.Example:For $i = 1 To $CMDLINE[0] Switch $CMDLINE[$i] Case 'parameter' ; do something Case 'other parameter' ; do something else EndSwitch Next Link to comment Share on other sites More sharing options...
GeoA Posted October 26, 2007 Author Share Posted October 26, 2007 Hey folks, Sorry I wasn't more clear on what $@ does--I'm stuck in my *nix world but asking for help in the Windows world. In this case $@ represents all the params passed to the function. MHz thanks for the code example. I can handle commandline args; I just can't do the same thing when I put the code into a function--can you tell me how to do that? Anyway, many years and many many shell scripts on *nix, this is my first foray into Windows scripting and I'm having fun. I hope to be able to get good enough with AutoIT to be able to help out in the future on this forum. Thanks again for any help that you can give me! G Link to comment Share on other sites More sharing options...
GeoA Posted October 28, 2007 Author Share Posted October 28, 2007 BUMP. lol, I need help here--anybody? Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 29, 2007 Share Posted October 29, 2007 BUMP. lol, I need help here--anybody? It's not strictly the main script's input parameters that are referenced. The declared function accesses its input parameters the same way. So here, $@ enumerates the inputs to the function doSomething(), not the parameters to the script that contains doSomething(). Still, the bash code is broken and unusable as an example. This would at least run in a bash shell, I think: # Pass all input parameters at once to doSomething() function doSomething("$@") # Handle inputs one at a time, and do... something function doSomething () { for i in $@ do case $i in blah) echo Received blah input. foo) echo Received foo input. bar) echo Received bar input. *) echo Input is not blah, foo, or bar: $i esac done } You can't strictly do this with AutoIt. You are not spawning a separate shell when you call an AutoIt function, so you don't use the same syntax to deal with parameters to the function that you use for command line parameters to the script. When you declare an AutoIt function you have to explicitly declare what the local variables containing the input parameters will be. Read the help file that comes with AutoIt and try some of the example scripts listed there. One option to do something at least similar is to accept an array as an input parameter, then just enumerate the array: Dim $avData[3] = ["Input One", "foo", "Input Three" ] doSomething($avData) Func doSomething($avInputs) For $i In $avInputs Switch $i Case "blah" ConsoleWrite("Received blah input." & @LF) Case "foo" ConsoleWrite("Received foo input." & @LF) Case "bar" ConsoleWrite("Received bar input." & @LF) Case Else ConsoleWrite("Input is not blah, foo, or bar: " & $i & @LF) EndSwitch Next EndFunc ;==>doSomething Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
GeoA Posted October 29, 2007 Author Share Posted October 29, 2007 Thanks, PsaltyDS! That'll do it. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now