Reliable way for a Bash script to get the full path to itself [duplicate]

Here’s what I’ve come up with (edit: plus some tweaks provided by sfstewman, levigroker, Kyle Strand, and Rob Kennedy), that seems to mostly fit my “better” criteria: SCRIPTPATH=”$( cd — “$(dirname “$0″)” >/dev/null 2>&1 ; pwd -P )” That SCRIPTPATH line seems particularly roundabout, but we need it rather than SCRIPTPATH=`pwd` in order to properly … Read more

Setting environment variables on OS X

Bruno is right on track. I’ve done extensive research and if you want to set variables that are available in all GUI applications, your only option is /etc/launchd.conf. Please note that environment.plist does not work for applications launched via Spotlight. This is documented by Steve Sexton here. Open a terminal prompt Type sudo vi /etc/launchd.conf … Read more

How to use glob() to find files recursively?

pathlib.Path.rglob Use pathlib.Path.rglob from the the pathlib module, which was introduced in Python 3.5. from pathlib import Path for path in Path(‘src’).rglob(‘*.c’): print(path.name) If you don’t want to use pathlib, use can use glob.glob(‘**/*.c’), but don’t forget to pass in the recursive keyword parameter and it will use inordinate amount of time on large directories. … Read more

mkdir -p functionality in Python [duplicate]

For Python ≥ 3.5, use pathlib.Path.mkdir: import pathlib pathlib.Path(“/tmp/path/to/desired/directory”).mkdir(parents=True, exist_ok=True) The exist_ok parameter was added in Python 3.5. For Python ≥ 3.2, os.makedirs has an optional third argument exist_ok that, when True, enables the mkdir -p functionality—unless mode is provided and the existing directory has different permissions than the intended ones; in that case, OSError … Read more

How to permanently set $PATH on Linux/Unix [closed]

You need to add it to your ~/.profile or ~/.bashrc file.  export PATH=”$PATH:/path/to/dir” Depending on what you’re doing, you also may want to symlink to binaries: cd /usr/bin sudo ln -s /path/to/binary binary-name Note that this will not automatically update your path for the remainder of the session. To do this, you should run: source … Read more

Path.Combine for URLs?

Uri has a constructor that should do this for you: new Uri(Uri baseUri, string relativeUri) Here’s an example: Uri baseUri = new Uri(“http://www.contoso.com”); Uri myUri = new Uri(baseUri, “catalog/shownew.htm”); Note from editor: Beware, this method does not work as expected. It can cut part of baseUri in some cases. See comments and other answers.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)