On Sun, 24 Nov 2013, Andrew Stevenson wrote:
> I am wondering what the fish equivalent of tcsh's (and other shells)
> word expansion modifiers? By word expansion modifiers I am talking about
> the ability to do things like:
>
> set version 5.9
> set major $version:r
> set minor $version:e
> set roman $version:s/1/I/:s/2/II/:s/3/III/:s/4/IV/
>
> for example. Presumably I could do some pipeline with echo and sed but
> I'm hoping there is a more elegant method.
>
> The context is that I am trying to convert my tcsh setting to fish. Take
> this snippet as an example:
>
> switch ($OENV)
> case 'aix':
> if (${OENVVER:r} >= 5) then
> setenv ARCH `uname -p`
> endif
>
> Apart from the fact that I will hopefully never use AIX 4 again what would be
> the fish way to deal with this?
The short answer is that there are no similar functions directly in fish.
The 'h', 't', and 'r' modifiers can be achieved using basename(1) and
dirname(1), 'u' and 'l' with tr(1), and 's' with sed(1).
The long answer is that comparing version numbers in shell is a common and
difficult task. Stack Overflow is full of people trying, and autoconf
ships with a special macro (AS_COMPARE_VERSIONS) which uses awk.
GNU sort and ls have an option to do version comparison (`sort -V` and `ls
-v`) but unfortunately that is not present on non-GNU systems.
In the general case it is often easier to do feature detection than OS
detection (like in web development):
`uname -p 2>/dev/null >/dev/null; and set -g ARCH (uname -p)` might work.
Alternatively, you could take the awk script from Autoconf and use that.
Perhaps it is something we could consider shipping.
As a last resort, without warranty:
```
if [ ( echo $OENVVER | cut -d . -f 1 ) -ge 5 ]
set -g ARCH (uname -p)
end
```
David Adam
[email protected]
------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT
organizations don't have a clear picture of how application performance
affects their revenue. With AppDynamics, you get 100% visibility into your
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349351&iu=/4140/ostg.clktrk
_______________________________________________
Fish-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fish-users