I want to find out if the PWD contains a certain directory name in it, it should be able to test it being anywhere in the output.
For example I have structure paths like public/bower_components/name/
and also have paths which are just public
.
I want to test because the contents of the folder name
move into the public folder and the bower_components
folder is removed.
Thanks
To determine the exact location of the current directory at a shell prompt and type the command pwd. This example shows that you are in the user sam's directory, which is in the /home/ directory. The command pwd stands for print working directory.
By default, bash shows just your current directory, not the entire path. To determine the exact location of your current directory within the file system, go to a shell prompt and type the command pwd. This tells you that you are in the user sam's directory, which is in the /home directory.
The pwd display name of current or working directory. The current working directory as set by the cd command stored in $PWD shell variable.
To print the current working directory, we use the pwd command in the Linux system. pwd (print working directory) – The pwd command is used to display the name of the current working directory in the Linux system using the terminal.
You can use BASH regex for this:
[[ "$PWD" =~ somedir ]] && echo "PWD has somedir"
OR using shell glob:
[[ "$PWD" == *somedir* ]] && echo "PWD has somedir"
You can use case
:
case "$PWD" in */somedir/*) …;; *) ;; # default case esac
You can use [[
:
if [[ "$PWD" = */somedir/* ]]; then …
You can use regex:
if [[ "$PWD" =~ somedir ]]; then …
and there are more ways, to boot!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With