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.
  • 38,596
  • 16
  • 96
  • 104
la1
  • 499
  • 1
  • 7
  • 26
  • 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
criptobadia
  • 1,984
  • 1
  • 17
  • 30
  • 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