0

I have a generic filepath- /home/aa/bb/cc/d.txt and want to script something like this-

so in the script, one thing would be for it to take that /path/to/testcase/d.txt

And split it into

working_dir = /path/to/testcase

netlist = d.txt

then the script would do:

cd $working_dir

<run $netlist>

I want to use basename and dirname to split the filepath here. Can anyone help me with this?

Expecting to run a testcase from a particular file path but making the command line generic for everyone to use.

Fravadona
  • 13,917
  • 1
  • 23
  • 35

1 Answers1

1

We have 2 native linux commands basename & dirname which will be perfect for your requirement. These commands comes with package coreutils.

Here is an example:

$ dirname /usr/local/xyz/home/test/foo.bar
/usr/local/xyz/home/test

$ basename /usr/local/xyz/home/test/foo.bar
foo.bar

Hope this helps you.

nightWolf
  • 11
  • 4
  • While those commands are provided by `coreutils` in Linux, they are defined by POSIX and available on any UNIX/Linux system – Fravadona Aug 25 '23 at 05:59