0

I have:

$ module avail firefox --latest
---------------------------------------------------------- /env/common/modules -----------------------------------------------------------
firefox/83.0

I would like to extract the firefox/83.0 part of the above result into a new command:

$ module load firefox/83.0

This is what I have so far, but it does not seem like I can pipe the result from the grep onto the next command:

$ module avail firefox --latest | grep firefox | echo module load 

Note: this is on a version of Modules which does not have the module load app/latest ability.

fredrik
  • 9,631
  • 16
  • 72
  • 132

3 Answers3

1

Use a regex to capture only firefox/83.0, then use command substitution to use that result in the next command;

module load $(module avail firefox --latest | sed -nre 's/^firefox\/[^0-9]*(([0-9]+\.)*[0-9]+).*/\0/p'

More info on the regex: How to extract a version number using sed?


Using xargs;

module avail firefox --latest | sed -nre 's/^firefox\/[^0-9]*(([0-9]+\.)*[0-9]+).*/\0/p' | xargs module load
0stone0
  • 34,288
  • 4
  • 39
  • 64
0
module load "$(module avail firefox --latest | grep -Eo 'firefox\/[[:digit:]]+\.[[:digit:]]+')"

Use the output of the module avail command and then search for firefix, followed by a / and then a digit one or more times, a full stop and then a digit one or more times. use this output as part of the module load command

Raman Sailopal
  • 12,320
  • 2
  • 11
  • 18
0

it does not seem like I can pipe the result from the grep onto the next command:

You can, but you need to use other command, that will read from the pipe and add it as command arguments. As simple as:

$ module avail firefox --latest | grep firefox | xargs module load 
KamilCuk
  • 120,984
  • 8
  • 59
  • 111