Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [dirname]

The tag has no usage guidance.

2
votes
2answers
142 views

dirname appears not to work with xargs

xargs and basename work together as I would expect: $ printf '%s\n' foo/index.js bar/index.js baz/index.js | xargs basename index.js index.js index.js xargs and dirname, though, appear not to work ...
0
votes
1answer
60 views

How can I use an argument from xargs to evaluate another expression?

I would like to evaluate a basename expression given an argument from xargs. I tested: find . -name '*.txt' | xargs -I f cp f DIR_OUT/copied_$(basename f) which gives no file or directory because $(...
1
vote
2answers
35 views

Get container directory more easily

I have a bash script here: $GOPATH/ src/ build.sh and in build.sh I have: export GOPATH="$(cd $(dirname "$BASH_SOURCE") && pwd)" is there a shorter way to get the containing dir ...
-1
votes
1answer
350 views

Using bash, resolve absolute path to relative path

Say I have this simple bash script: #!/usr/bin/env bash file="$1"; if [ -z "$file" ]; then echo "Must pass relative file path as the first argument."; fi git_root=`git rev-parse --show-...
0
votes
2answers
239 views

Apply readlink to a non-symlink file?

The following code from https://stackoverflow.com/a/920834/156458is to get the pathname to the parent directory of a script inside the script, even if the script is run via a symlink to it: if [ -L ...
0
votes
2answers
105 views

Bash for file processing [duplicate]

I am writing a bash script to move all images into a central file. I create the list of image files with: img_fil='/home/files/img_dump.txt' locate -i image | grep \.jpg > "$img_fil" locate -i ...
0
votes
1answer
41 views

How can I set ENV from a path

I just installed android-sdk using Homebrew. The path is /usr/local/Caskroom/android-sdk/3859397,26.0.1. I know I can export ANDROID_HOME with that value. How can I set it dynamically using the ...
0
votes
3answers
452 views

cd 3 times to great-grandparent dir

I have this: cd $(dirname $(dirname $(dirname "$0"))) && which will cd to project root. Is there shorthand for this somehow, where I can just be like: cd 3 && # not quite, but you ...