0

I need to split the file path/directory and use it as an argument using shell script.

I have a file path: /home/ubuntu/testscriptsfolder/jmx/*.jmx and need to get only *.jmx in my variable so that I can pass it as an argument in one of my run commands.

Please suggest how it is achievable in shell script.

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
la1
  • 519
  • 1
  • 8
  • 30
  • 1
    Possible duplicate of [unix shell script - extract file name](http://stackoverflow.com/questions/2536046/unix-shell-script-extract-file-name) – SLePort Mar 17 '17 at 13:22
  • You could try parameter substitution using ## – grail Mar 17 '17 at 13:41

1 Answers1

2

These commands are useful for that:

$ basename /path/to/name
name
$ dirname /path/to/name
/path/to
aicastell
  • 2,182
  • 2
  • 21
  • 33
  • Thanks for sharing info. However when tried with basename /path/to/name, can get only one file name whereas I have to iterate through all the files (10 .jmx files are present). Please suggest. – la1 Mar 20 '17 at 09:26