add icloud destination to path in terminal - macos

I want to add destination of iCloud drive folder to PATH in terminal.
I tried to add this line to .bash_profile (that path works with cd command)
export PATH="~/Library/Mobile\ Documents/com~apple~CloudDocs/Scripts:$PATH"
and nothing happened. Even ...com\~apple\~CloudDocs... doesn't work.
After calling echo $PATH, there was added entire path to iCloud drive exactly how I wanted. But when I call any of scripts located in that path No such file or directory error occurs.
When I rewrite .bash_profile file to export export PATH="~/.Scripts:$PATH" and relocate scripts there, everything works.

After doing a little bash code analysis, it looks like if your path beings with ~, then any subsequent ~ in the path is affected.
From tilde.c
/* Scan through STRING expanding tildes as we come to them. */
while (1)
Instead of using ~/Library/...,
try /Users/[user]/Library/...

Related

commands work in home directory, but not anywhere else

I'm trying to set up a dev environment on my Mac Mini running Bir Sur 11.2.3. I can add commands to the .zshrc file, but they only seem to work in my home directory. For example...
chris#chriss-mac-mini an_app % which flutter dart
flutter not found
dart not found
chris#chriss-mac-mini an_app % cd ~
chris#chriss-mac-mini ~ % which flutter dart
dev/flutter/bin/flutter
dev/flutter/bin/dart
My .zshrc file looks like this...
chris#chriss-mac-mini ~ % cat .zshrc
export PATH="$PATH:dev/flutter/bin"
Why am I unable to use the flutter command in other directories on this machine?
Short answer: change the line in your .zshrc to this:
export PATH="$PATH:$HOME/dev/flutter/bin"
Long answer: the path you added to your PATH environment variable, dev/flutter/bin, doesn't start with "/" so it's a relative path, meaning it'll be resolved relative to wherever your current working directory happens to be. If you're in /Users/cjmcqueen (or whatever your home directory is), it'll resolve to /Users/cjmcqueen/dev/flutter/bin, which is presumably where the actual binaries are. But if you're in /random/other/path, it'll resolve to /random/other/path/dev/flutter/bin, which probably doesn't even exist (let alone contain binaries for the flutter, dart, etc commands).
To solve this, you need to add a full absolute path to the binaries, instead of a relative one. In some situations, ~ will expand to the path to your home directory (so ~/dev/flutter/bin will work), but not in all situations. In this particular situation, $HOME is better because the shell will expand it to the absolute path to your home directory before storing it in the PATH variable, so you don't have to depend on something else resolving it later.
export PATH="$PATH:dev/flutter/bin" is referencing a relative path.
dev/flutter/bin should be something like /Users/<user>/dev/flutter/bin.
In the terminal, go to the directory for your flutter bin folder and type pwd. This is the full path it should reference.

How to add an alias to .bashrc file?

I am new to Ubuntu. I need to set path in my .bashrc file, but I am getting permission denied error even if am the admin of the system .
export TCFRAME_HOME=~/tcframe
alias tcframe=$TCFRAME_HOME/scripts/tcframe
Now when I type tcframe version I get
bash: /home/p46562/tcframe/scripts/tcframe: No such file or directory
How to fix this?
The error message is telling you that you are trying to execute a file which does not exist.
We can vaguely guess about what files do exist, but without access to your system, we can't know for sure what you have actually installed and where.
Perhaps you have a file named tcframe in a directory called scripts in your home directory?
alias tcframe=$HOME/scripts/tcframe
A common arrangement to avoid littering your environment with one or more aliases for each random utility you have installed somewhere is to create a dedicated directory for your PATH - a common convention is to call it bin - and populate it with symlinks to things you want to have executable.
Just once,
mkdir $HOME/bin
and edit your .profile (or .bash_profile or .bashrc if you prefer) to include the line
PATH=$HOME/bin:$PATH
From now on, to make an executable script accessible from anywhere without an explicit path, create a symlink to it in bin;
ln -s $HOME/scripts/tcframe $HOME/bin
Notice that the syntax is like cp; the last argument is the destination (which can be a directory, or a new file name) and the first (and any subsequent arguments before the last, if the last is a directory) are the sources. When the destination is a directory, the file name of each source argument is used as the name of a new symlink within the destination directory.
Also notice that you generally want to use absolute paths; a relative path is resolved relative to bin (so e.g.
ln -s ../scripts/tcframe $HOME/bin
even if you are currently in a directory where ../scripts does not exist.)
Scripts, by definition, need to be executable. If they aren't, you get "permission denied" when you try to run them. This is controlled by permissions; each file has a set of permission bits which indicate whether you can read, write to (or overwrite), and execute this file. These permissions are also set separately for members of your group (so you can manage a crude form of team access) and everyone else. But for your personal scripts, you only really care that the x (executable) bit is set for yourself. If it isn't, you can change it - this is only required once.
chmod +x scripts/tcframe

How to change $PATH variable in bash_profile in OSX?

I am trying to install a 3rd party library from GitHub through terminal. Before this installed Anaconda Python distribution on my system and that has modified my root directory of my terminal to;
Vinos-MBP:~ Vino$
So when try to navigate to a particular directory to install the said library using
cd /Users/Vino/<install location>
The terminal prints the following message;
-bash: cd: /Users/Vino/Documents/My: No such file or directory
I know this problem is because Python has modified my bash_profile startup file. I tried various online methods to fix this issue, but nothing actually works. Whenever I restart my terminal and navigate using cd, I get the same error. How do I reset $PATH to $HOME (like as before installing Anaconda), so that I can navigate to any folder on my system?
This is not a problem with $PATH or $HOME -- it looks to me like you have a space in the folder name, and aren't properly quoting/escaping it. If they aren't quoted or escaped, spaces are taken as separators between arguments (e.g. folder paths) rather than part of the path. If the folder you're trying to cd to is "/Users/Vino/Documents/My Installation Location", you could use any of these:
cd "/Users/Vino/Documents/My Installation Location"
cd '/Users/Vino/Documents/My Installation Location'
cd /Users/Vino/Documents/My\ Installation\ Location
cd ~/Documents/My\ Installation\ Location
cd ~/"Documents/My Installation Location" # Note that the ~/ part must not be quoted
There are a number of other characters that're perfectly legal to have in filenames that will cause trouble when used on the command line without quotes or escapes (including the quote and escape characters themselves!). One way to avoid trouble is to drag-and-drop an item from the Finder into the Terminal window, and it'll fill in a (properly escaped) path to that item.

iverilog environment set up on macbook

I tried to make iverilog command s.t I can run verilog program on my Macbook Air.
After few steps for installing the files, the tutorial told me to type:
export PATH=~/bin:/usr/local/iverilog/bin
It worked in terms of iverilog command, i.e, I can compile .v file. However, normal command like ls, man,etc.
I guess it is the problem of the PATH of the command sets, which means those normal unix command is not located.
Can someone tell me how to fix it and I dont need to export the PATH everytime?
You didn't add your paths to the current paths established by the OS. Instead, you replaced it with your paths. This is what you need to do in order to add paths to your PATH variable:
export PATH=$PATH:~/bin:/usr/local/iverilog/bin
The $PATH part is your current PATH value, which is added (concatenated actually) to the list of new paths you want to add. This is turn is assigned to PATH variable.
To make this additions permanent, you may want to add the above line to the end of your .profile file, or .bash_profile (whatever you have in OS X)
You can also do as this:
http://architectryan.com/2012/10/02/add-to-the-path-on-mac-os-x-mountain-lion/
Which says that you can edit the file /etc/paths and add whatever paths you want to add, one per line, then save that file and your added paths are available. In this case, just remember to use absolute paths. That is, paths starting with / . The first one you use: ~/bin is not an aboslute path. You need to convert it to an absolute path. To do this, remember that ~ is a shortcut to your HOME directory: something like /Users/myloginname. Type echo $HOME to find it out.

How to remove entry from $PATH on mac

I was trying to install Sencha Touch SDK tools 2.0.0 but could not run it properly. It created an entry in the $PATH variable.
Later I deleted the sencha sdk tools folder but didn't realize that the path variable is still there.
When i did echo $PATH I got -
/Applications/SenchaSDKTools-2.0.0-beta3:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
I searched on how to remove variables from $PATH and followed these steps :
Gave the command PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin"
Did echo $PATH which showed /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
gave the command export PATH
Closed terminal and reopened it. Gave the command echo $PATH. This time I got
/Applications/SenchaSDKTools-2.0.0-beta3:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
Can anyone tell me what am i doing wrong?
echo $PATH and copy it's value
export PATH=""
export PATH="/path/you/want/to/keep"
Check the following files:
/etc/bashrc
/etc/profile
~/.bashrc
~/.bash_profile
~/.profile
~/.MacOSX/environment.plist
Some of these files may not exist, but they're the most likely ones to contain $PATH definitions.
On MAC OS X Leopard and higher
cd /etc/paths.d
There may be a text file in the above directory that contains the path you are trying to remove.
vim textfile //check and see what is in it when you are done looking type :q
//:q just quits, no saves
If its the one you want to remove do this
rm textfile //remove it, delete it
Here is a link to a site that has more info on it, even though it illustrates 'adding' the path. However, you may gain some insight.
What you're doing is valid for the current session (limited to the terminal that you're working in). You need to persist those changes. Consider adding commands in steps 1-3 above to your ${HOME}/.bashrc.
If you're removing the path for Python 3 specifically, I found it in ~/.zprofile and ~/.zshrc.
$PATH contains data that is referenced from actual files. Ergo, you should find the file containing the reference you want to delete, and then delete said reference.
Here is a good list to run through progressively [copied from #Ansgar's answer with minor updates].
/etc/bashrc
/etc/profile
~/.bashrc
~/.bash_profile
~/.profile
~/.MacOSX/environment.plist
/etc/paths
/etc/paths.d/
Note that /etc/paths.d/ is a directory that contains files with path references. For example, inside this directory may be a file called, say, fancy-app, and inside this file you'll see an entry like below:
/path/to/fancy-app
This path will appear in your $PATH and you can delete the entry in the file to remove it, or you can delete the file if it has only the one reference you want to remove.
Use sudo pico /etc/paths inside the terminal window and change the entries to the one you want to remove, then open a new terminal session.
when you login, or start a bash shell, environment variables are loaded/configured according to .bashrc, or .bash_profile. Whatever export you are doing, it's valid only for current session. so export PATH=/Applications/SenchaSDKTools-2.0.0-beta3:$PATH this command is getting executed each time you are opening a shell, you can override it, but again that's for the current session only. edit the .bashrc file to suite your need. If it's saying permission denied, perhaps the file is write-protected, a link to some other file (many organisations keep a master .bashrc file and gives each user a link of it to their home dir, you can copy the file instead of link and the start adding content to it)
Close the terminal(End the current session). Open it again.
If the manual export $PATH method does not seem to be working after you close the terminal and open again, definitely check the shell configuration files.
I found a small script that kept adding some more path in front of the $PATH everytime it was open.
For zsh you can check the ~/.zshrc file.

Resources