Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
115 user(s) are online (108 user(s) are browsing Forums)

Members: 1
Guests: 114

Amigafreak02, more...

Support us!

Headlines

 
  Register To Post  

AmigaDOs env variable help
Quite a regular
Quite a regular


See User information
Hi,

A little help required, if I do this:

How do I combine an env variable together with a regular string for file operations?

i.e.

setenv $test ram:
echo $test

This works okay, but what if I wanna do this?

delete $test/file.txt

Assuming the file exists it just reports: DELETE: object not found

Go to top
Re: AmigaDOs env variable help
Not too shy to talk
Not too shy to talk


See User information
Try

delete ${test}/file.txt

Edit: better ${test}file.txt

Your code resolves to ram:/file.txt which is not correct. The right path should be ram:file.txt.

Edit2: os4 contains some new shell commands which allow to connect and split file name components. I don't remember the names, but as they refer to the similar dos.library functions, they supposedly are addpart, filepart and pathpart.

Knowing that, your delete would probably be best like this:

set testfile `addpart $test file.txt`
delete $testfile

or

delete `addpart $test file.txt`


Go to top
Re: AmigaDOs env variable help
Quite a regular
Quite a regular


See User information
Greats thanks Thomas! So simply surround the variable in curly braces when you have to place a variable right next to regular text.

Works great. :)

Go to top
Re: AmigaDOs env variable help
Quite a regular
Quite a regular


See User information
Right, need further help!

What if the filepath contained in the env variable contains spaces? Where do I put the quote marks? Tried a few ways, none work.

EDIT: Anyone got any more tips I can add to my explanation of Environmental Variables? I have room for perhaps 2 more if you keep it short and sweet.

---

Environment variables are used in AmigaOS within script or batch script processing.
There are both global and local variables, and they are referred to with a dollar sign in front of the variable name, for example $myvar.
Global variables are available system-wide; local variables are only valid in the current shell. In case of name collision, local variables have precedence over global variables.\nGlobal variables can be set using the command SetEnv, while local variables can be set using the command Set.
There are also the commands GetEnv and Get that can be used to print out global and local variables.

Global variables are kept as files in ENV:, and optionally saved on disk in ENVARC: to survive reboot and power cycling. ENVARC: is an assign to SYS:Prefs/Env-archive where SYS: refers to the boot device.

Tip: Surround a variable in curly braces {} to construct a filepath if you are going to use a command such as 'Delete'.


Edited by djrikki on 2012/2/7 18:51:49
Edited by djrikki on 2012/2/7 18:52:33
Go to top
Re: AmigaDOs env variable help
Quite a regular
Quite a regular


See User information
Any one?

Go to top
Re: AmigaDOs env variable help
Just can't stay away
Just can't stay away


See User information
Quote:
Tip: Surround a variable in curly braces {} to construct a filepath if you are going to use a command such as 'Delete'.

it has nothing to do with "delete". It would work with other commands as well


The command Thomas was thinking about is OS4.1:C/PathPart


For the quotes:

setenv test ram disk:
setenv test2 `pathpart "${test}" file.txt`
echo $test2
ram disk:file.txt

Of course if you want to use the variable with the space you need to use "$test2" instead. Easy

Philippe 'Elwood' FERRUCCI
Sam460ex 1.10 Ghz
http://elwoodb.free.fr
Go to top
Re: AmigaDOs env variable help
Quite a regular
Quite a regular


See User information
Doesn't seem to answer the question: do this

cd ram:
echo hello >ram:test.txt
setenv test ram disk:
delete {$test}test.txt

result: AmigaDOS Process window, please insert volume disk:

Go to top
Re: AmigaDOs env variable help
Just can't stay away
Just can't stay away


See User information
@djrikki

setenv txtfile `pathpart "${test}" file.txt`
delete "$txtfile"

Go to top
Re: AmigaDOs env variable help
Quite a regular
Quite a regular


See User information
Excellent, thanks guys!


Edited by djrikki on 2012/2/8 0:05:26
Go to top
Re: AmigaDOs env variable help
Just can't stay away
Just can't stay away


See User information
A few hints...

Use set instead of setenv and then use unset at the end of your scripts to tidy up.

Sometimes if your inserting a variable into a string that has an underscore you have to escape the underscore with a *. eg.

copy "CD0:VIDEO_TS/VTS_0$number*_1.VOB"

Sometimes you have to use a ' to escape characters.

If you want to have quotes round filenames in lists gernerated by the list command you need to escape them with *, this also works with the echo command. eg.

list dh0: all files pat "#?.info" lformat "delete *"%P%N*"" to ram:script

Also remember that because you use * as an escape character in the list command you cannot use it as a wildcard so pat *.info would not work in the above example.

Amiga user since 1985
AOS4, A-EON, IBrowse & Alinea Betatester

Ps. I hate the new amigans website. <shudder>
Go to top
Re: AmigaDOs env variable help
Just can't stay away
Just can't stay away


See User information
@djrikki

I understand you are working on a tutorial on using environmental variables.
Why not have a look how Gui4Cli uses these. Not only can you of course use all the CLI commands you will describe, but here are few Gui4Cli plus
- Under Gui4Cli when you name a variable .MyVar, this is an environmental variable, which will appear in env: as env:.MyVar

As for normal Gui4Cli variables you will be able to use constructs such as

YourVar = $.MyVar[0][5] (first 5 characters)
YourVar = $.MyVar[-5] (last 5 characters)
etc.l
You can easily load the file env:.MyVar in a listview and manipulate the lines of a multiline environmental variable

You can also define a set of (normal or environmental) variables
MyVar1, MyVar2, MyVar3
and get their values with
i = 3
YourVar = $MyVar$i






Go to top
Re: AmigaDOs env variable help
Quite a regular
Quite a regular


See User information
Quote:

djrikki wrote:
Doesn't seem to answer the question: do this

cd ram:
echo hello >ram:test.txt
setenv test ram disk:
delete {$test}test.txt

result: AmigaDOS Process window, please insert volume disk:


in your example the definite brackets are displaced of one position, should be:

delete ${test}test.txt

Go to top
Re: AmigaDOs env variable help
Quite a regular
Quite a regular


See User information
@josduchit

Aye,each article is very short, its more of a knowledge-base than a tutorial so might have to divide environmental variables into two articles so I can cover as much as possible.

If you want to get an idea of how long an article can be simply download/use Jack and press F2 or click the boing-ball in the top-left. You can even submit your own articles to me if you feel so inclined- however I'd wait till the next version because its much bigger than the one in 2.9.1 which is unfinished.

The knowledge-base currently (yet to be released version) now has over 200 articles in it; you, me, anyone in the community can submit articles or any relevant subject matter for inclusion.

I am missing an article on portablE atm - so if ChrisH is reading this perhaps he can write me a passage or two as I am busy this evening and probably tomorrow as well with real work.

Go to top

  Register To Post

 




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




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project