Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
148 user(s) are online (127 user(s) are browsing Forums)

Members: 1
Guests: 147

AmigaSociety, more...

Support us!

Headlines

 
  Register To Post  

The GetEnv command
Quite a regular
Quite a regular


See User information
Hi folks,

Okay I understand the getenv commands looks in env: and types its contents to the screen, but how do anything useful with that variable other than output it to the screen?

Eg. imagine there is a variable called JOE and it contains the data: Bloggs

getenv JOE
Bloggs1.OS4.1:

---------

Can I do something like this?

copy $joe to ram:

if $joe = 'bloggs'
info
endif

Also if the variable is in fact multi-lined is there a way the AmigaShell can say get line 2 of it? Getenv only gets the first line, how could I get line x from this text file structure? What is the correct way to do this?

Finally if a text file on one line had: "joe","bloggs","is","such","a","lame","name" - a typical csv file format. Is there a script/way/command that can anyone can use to go through the 'fields' and print them to the screen or do anything else useful?

Thanks in advance.

Go to top
Re: The GetEnv command
Just can't stay away
Just can't stay away


See User information
You can use backticks (edit: this is what i've seem them referred to as. If they have another name, let me know).

copy `getenv JOE` to RAM:

etc..

Perhaps there's easier or better ways to use it.

Go to top
Re: The GetEnv command
Not too shy to talk
Not too shy to talk


See User information
Quote:
Can I do something like this?


Yes, you can, exactly the way you wrote it, except that you need to use double quotes and the equal operand is EQ, not =.

copy $joe to ram:

if 
$joe EQ "bloggs"
  
info
endif


Also note that it compares the entire variable, not a substring, so "bloggs" does not match "bloggs1.os4.1".

Quote:
Also if the variable is in fact multi-lined is there a way the AmigaShell can say get line 2 of it?


There is no such thing like a multi-lined variable. You can have files in ENV: which have multi lines (and there is a dos.library function which can treat an env varaible as binary and such return the entire content) but they are not variables in the sense of setenv / getenv.

Quote:
Is there a script/way/command that can anyone can use to go through the 'fields' and print them to the screen or do anything else useful?


Not yet, you need to write your own program for this.

Perhaps you should consider using ARexx as scripting language for such a complex task. It has file and string operations as part of the language.


Go to top
Re: The GetEnv command
Just can't stay away
Just can't stay away


See User information
Quote:
Also if the variable is in fact multi-lined is there a way the AmigaShell can say get line 2 of it? Getenv only gets the first line, how could I get line x from this text file structure? What is the correct way to do this?

If it could be done (and I don't think it can) it would probably be awkward to implement in a useful way.

Quote:
Finally if a text file on one line had: "joe","bloggs","is","such","a","lame","name" - a typical csv file format. Is there a script/way/command that can anyone can use to go through the 'fields' and print them to the screen or do anything else useful?

You could use the cut command like this:
cut "*"joe*",*"bloggs*"" word=1 separator=,
"joe" (result of above command)
Notice that the quotes had to be escaped with a *.

If you want to parse text, ARexx would be a better choice than AmigaDOS. You can execute AmigaDOS commands from ARexx and execute short ARexx scripts from AmigaDOS.

Go to top
Re: The GetEnv command
Just can't stay away
Just can't stay away


See User information
You can assign to a local variable too like:

set myvar `getenv joe`

if $myvar EQ Bloggs
echo OK
endif

Philippe 'Elwood' FERRUCCI
Sam460ex 1.10 Ghz
http://elwoodb.free.fr
Go to top
Re: The GetEnv command
Quite a regular
Quite a regular


See User information
Cool, as long as there are plenty of options out there. I am writing an application that has both a GUI and supports command line arguments so I just need a little understanding how someone would pick it up afterwards if the application wrote its output into a file stored in ENV:

More news to follow next week, hopefully should be ready for a Beta release next week.

One of many goals at the moment is building in catalog/language support as early as possible in the development, I have done preliminary work like keeping all 'words' in a single array. Next step is to discover the current language that is defined in AmigaOS and get them into this array - so just built-in English for the first few releases. After this, will need some volunteers to do some translating if the application.

Go to top
Re: The GetEnv command
Just can't stay away
Just can't stay away


See User information
note that you should write to Envarc/Env only settings, nothing else.

Philippe 'Elwood' FERRUCCI
Sam460ex 1.10 Ghz
http://elwoodb.free.fr
Go to top
Re: The GetEnv command
Supreme Council
Supreme Council


See User information
Quote:

djrikki wrote:
One of many goals at the moment is building in catalog/language support as early as possible in the development, I have done preliminary work like keeping all 'words' in a single array. Next step is to discover the current language that is defined in AmigaOS and get them into this array - so just built-in English for the first few releases. After this, will need some volunteers to do some translating if the application.


You don't need to store all the translations, these are stored in the language specific catalogs. If you want to have a built-in default language, they are usually stored in the catalog descriptor source file. What this basically means is that you create a file that holds all the words that should be translated. Both the translators and your program use this file. One to build the catalog, and the other for the default strings respectively.

Have a look at the CatComp documentation for more information.

Simon

Comments made in any post are personal opinion, and are in no-way representative of any commercial entity unless specifically stated as such.
----
http://codebench.co.uk
Go to top
Re: The GetEnv command
Just can't stay away
Just can't stay away


See User information
Quote:

djrikki wrote:
I am writing an application that has both a GUI and supports command line arguments so I just need a little understanding how someone would pick it up afterwards if the application wrote its output into a file stored in ENV:

You might consider using the PIPE: device. Or if you must write to a "regular" file, do it in T: instead of ENV[ARC]:.

I'm assuming this is just a temporary file for communication between modules? If it is something you need persisted after your application (and possibly the system) shuts down, you should write a regular file instead, in a location chosen by the user via a file requester (and possibly set/save the path through the preferences of the program if you want to save the user from selecting the path/file every time).

Best regards,

Niels

Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project