Running executable script from iCloud folder - bash

I'm running an executable script from my iCloud folder. I get the following error
"ERROR: run_shell_command on /Users/username/Library/Mobile Documents/com~apple~CloudDocs... /bin/bash: /Users/username/Library/Mobile: No such file or directory"
which has to do with the space between "Mobile" and "Documents" in the iCloud path. How do you handle these cases. I'm sure there is an easy solution but I can't figure it out.
I've checked running the script in my local machine and it works. However, I would prefer to do this from the cloud to optimize space.
Thank you

Spaces are escaped with the \ character.
For example:
cd /Users/username/Library/Mobile\ Documents
You can also enclose the argument in quotes:
cd '/Users/username/Library/Mobile Documents'

This solves the space-in-path problem on iCloud Drive persistently:
# bash 5 will expand $HOME to your home dir path.
# Or, replace '$HOME' with /Users/<username>
cd ~
ln -s "$HOME/Library/Mobile\ Documents/com~apple~CloudDocs" icloud
cd ~/icloud
From ~/icloud I enjoy command line access. My bash autocomplete works. I can ignore the tildes and space. I use unix naming for the files and directories below ~/icloud, to make script access easier.
#cmartinezvil if you get tired of quoting paths every time, the symlink is handy. You can get the docs using info ln on MacOs.
Thanks go to #jl-peyret for this answer.
https://apple.stackexchange.com/questions/428604/how-to-make-icloud-drive-conveniently-available-to-the-shell/448685#448685

Related

source a file in .zshrc does not find the file

I'm using zsh on Catalina and I have some problems with sourcing (dunno if that's the correct term) a file in my .zshrc file that has a white space in the path.
Basically what I'm trying to achieve is to have my personal zsh settings in iCloud so that it syncs between all my computers. There is a white space in the path to my iCloud directory that I can't change.
~/Library/Mobile Documents/com~apple~CloudDocs/
Escaping the wihte space does not work when I try it.
file='~/Library/Mobile\ Documents/com~apple~CloudDocs/file.sh'
source $file
Results in:
.zshrc:source:29: no such file or directory: ~/Library/Mobile\ Documents/com~apple~CloudDocs/file.sh
It works fine when I manually do:
source ~/Library/Mobile\ Documents/com~apple~CloudDocs/file.sh
Any ideas on how to solve this or I'm I back at manually load my files?
The quotes are ruining your day, and the excaped space doesn't make much sense either, because you are quoting the whole stuff anyway:
file='~/Library/Mobile\ Documents/com~apple~CloudDocs/file.sh'
This means that you need a directory with the name ~.
You could write it as
file=~/Library/Mobile\ Documents/com~apple~CloudDocs/file.sh
which would substitute the tilde by your home directory. I personally would use double quotes and write it as:
file="$HOME/Library/Mobile Documents/com~apple~CloudDocs/file.sh"

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.

MacOS Terminal go to a folder with spaces and parenthesis

I'm trying to configure Cyberduck to read the Bookmark files from my Dropbox folder.
This is usually accomplished by this command:
defaults write ch.sudo.cyberduck application.support.path ~/Dropbox/Cyberduck
Super easy!!
But... Dropbox has since changed and if you have a Pro Account the Dropbox folder is renamed "Dropbox (Personal)".
I've tried to do this:
defaults write ch.sudo.cyberduck application.support.path ~/Dropbox\ \(Personal\)/
And I get this error:
not parse: [...]/Dropbox (Personal)/Apps/Cyberduck/. Try single-quoting it.
I tried single quoting like this but same error:
defaults write ch.sudo.cyberduck application.support.path '~/Dropbox\ \(Personal\)/'
How can I solve this?
You can single quote escape your parentheses by wrapping them in a double quote:
Instead of: ln -s '/Users/username/Dropbox (Company Name)/' DropboxCompanyName
Do: ln -s "'/Users/username/Dropbox (Company Name)/'" DropboxCompanyName
Notice the double quotes added to /Users/username/Dropbox (Company Name)/
So I cannot find a way to do a "defaults write" to a path with parentheses, but I did this workaround and it seemed to work for me (in my case I needed to link to my enterprise Dropbox account):
cd to your home folder and create a symlink of the directory that has the parentheses:
ln -s '/Users/username/Dropbox (Company Name)/' DropboxCompanyName
At that point, I was able to do do a defaults write that wrote ~/DropboxCompanyName as part of the path and it worked just fine.
All that said, your personal folder already has a hidden symlink: "Dropbox" that's in the same directory and pointing to "Dropbox (Personal)", so you should be able to do you original command as such:
defaults write ch.sudo.cyberduck application.support.path ~/Dropbox/Cyberduck
… because the "Dropbox" part of the path should still lead to your personal folder. This both what I've observed locally (when viewing hidden files) and what Dropbox says on their site: https://www.dropbox.com/help/9031
I am assuming you are using Unix in Terminal.
I have set up a folder of the same name in my Public Folder to test as shown below.
Your current referencing to the folder would seem correct. Dragging the folder into the Terminal window current command line will automatically give you the correct referencing to that folder.
As an alternative I suggest putting the name of the folder in double quotation marks. Even though there are brackets in the name, there is no need to escape these characters in Unix in Terminal in this instance when using double quotation marks. This makes it easier to humanly type the correct reference.
To reference a folder in the image below, for example, the following referencing works for the cd (change directory command):
~/Public/"Dropbox (Personal)"
Hence I suggest try:
ch.sudo.cyberduck application.support.path ~/Public/"Dropbox (Personal)"
As for the rest of this command, I am not sure that ch is a valid Unix command. I do not yet have enough Unix experience to guide you from here.
you have to put "" in the whole address
more like this
ch.sudo.cyberduck application.support.path "~/Public/Dropbox (Personal)"

Git Bash for Windows showing/expecting file paths with forward-slashes, no drive colon

I installed Git Extensions which automatically downloaded and installed Git for Windows, and when I use Git Bash, it shows the file path as /c/whatever/folder rather than C:\whatever\folder, and if I paste in a path from Windows Explorer, it chokes on it because it's expecting forward-slashes and no colon after the drive letter.
When I installed Git for Windows by itself previously, it showed the slashes/colon properly, but was much more limiting and harder to use (especially with copy/paste).
Why is it showing/expecting file paths with slashes and no colon, and how do I fix it?!
http://imgur.com/vMc7fU6
You could also try adding single quotes in the directory path copied from Windows Explorer and pasted in the Terminal prompt (e.g. cd 'D:\Documents\Developer Tools & Docs'). It worked for me. Check out the solution posted in the following link:
Escaping backslash in windows paths passed to unix programs
It's getting tripped up because the \ is an escape character in the Unix/Linux world. If the path you paste is like c:\\somefolder\\anotherfolder, it would be ok, because \\ says "I want a literal \. That said, my git bash understands a single \ as long as the path does not end with it. So cd c:\folder works, but cd c:\folder\ does not work.
BTW what error message is it giving you when it chokes, and can you give an example of a pasted path it chokes on.
This is caused by the Git Bash (Ming) shell, not because of anything git itself is doing.
If you run the mount command inside this shell, you will find that /c/ is the folder where your hard drive is mounted. If you want Git Bash to use a different folder name for your hard disk, you can map your disk to a different folder.
By the way, you shouldn't have to care about this when using git. Repos typically don't (and typically shouldn't) contain files in the root directory of a volume. Even if they did, git references files relative to the repository root. Since any folder that is the root level of a volume will also be the root level of any repo it's in, it will be called / in git, regardless of how the underlying operating system or shell labels it.
For your convenience, here is the output of mount from inside Git Bash on my laptop. You should get similar results. You can see that it indicates that C:\ is mounted on the /c folder.
chris#caerdydd MINGW64 ~
$ mount
C:/Program Files/Git on / type ntfs (binary,noacl,auto)
C:/Program Files/Git/usr/bin on /bin type ntfs (binary,noacl,auto)
C:/Users/chris/AppData/Local/Temp on /tmp type ntfs (binary,noacl,posix=0,usertemp)
C: on /c type ntfs (binary,noacl,posix=0,user,noumount,auto)

How can I cd to an alias directory in the Mac OSX terminal

Is there a way to get into an alias directory from shell with the command "cd" ? It always returns that "htdocs" isn't a directory.
Edit: I made the shortcut with the OS GUI -> rightclicked the htdocs directory and chose "Alias..." (i'm using a german OS if it's not alias maybe it's called shortcut in english?) then i moved it to my home directory (because my terminal starts from there when i open it).
All i want is to open my terminal and type "cd htdocs" so that i can work from there.
you can make symbolic link to it.
ln -s EXISTING_PATH LINK_NAME
e.g.
ln -s ~/Documents/books ~/Desktop/
Reference
Enter into a directory through an alias in Mac OS X terminal
All i want is to open my terminal and type cd htdocs so that i can work from there.
The easier approach is probably to ignore the links and add the parent directory of your htdocs directory to the CDPATH environment variable. bash(1) will check the contents of the CDPATH environment variable when you type cd foo to find the foo directory in one of the directories listed. This will work no matter what your current working directory is, and it'll be easier than setting symbolic links.
If the path to your htdocs is located /srv/www/htdocs/, then you could use CDPATH=/srv/www. Then, cd foo would first look for /srv/www/foo/ and change to it if it exists; if not, then it would look for foo in the current working directory and change to it if it exists. (This might get confusing if you have multiple htdocs directories on your system; in that case, CDPATH=.:/srv/www would let you change into a child directory easily but still use the /srv/www/htdocs/ version if no ./htdocs directory is present.)
You can add the CDPATH=/srv/www line to your ~/.bashrc file so it works every time you start a terminal.
I personally use this to quickly work in the directory which is present deep inside one of my Volumes in my Mac.
Open your ~/.bash_profile, create an alias to the directory by adding this:
alias cdh="cd /Volumes/Haiku/haiku/src/apps/superprefs"
Save it, restart your terminal. Now on typing cdh in your terminal should change the working directory to the one mentioned as the alias.
I am not sure how OSX exposes Alias links but since you are using bash you can just create a variable in your .bashrc file.
On its own line put:
htdocs=YourDirectoryPath/
Once you have restarted bash you can just type cd $htdocs
There is a old hint on macworld to do this in a way that is integrated with BASH: Enable 'cd' into directory aliases from the Terminal
Plus, here is an answer that uses this solution on superuser.
You may be able to use osascript to do this -- this command seems to work:
cd "`osascript -e "on run aFile" -e "set aFile to POSIX file aFile as alias" -e "tell application "\""Finder"\"" to return POSIX path of ( ( original item of aFile ) as text ) " -e "end run" path_to_my_Finder_alias 2>/dev/null`"
Basically this command is running an AppleScript that finds the destination path of the argument (path_to_my_Finder_alias) in a subshell, then wraps it in double quotes, and changes the directory to it.
Maybe someone with a little more bash expertise can turn it into a bash alias or function.
try:
alias cdgo=`echo cd /root/go/`
cdgo will run, then get command "cd /root/go/" and enter, and it will change your directory in current terminal process
It works on my centos, no test with osx

Resources