I have a perl script that takes input file path from the terminal. So, while entering the file path, I can drag and drop the file to the terminal (Mac). If I have file paths like
/Users/San/abc(ev50)_xyz.tif,
then dragging and dropping the file will result in
/Users/San/abc\(ev50\)_xyz.tif
being pasted on the terminal. Is there a way to copy paste (drag and drop) the file path as is? I saw in some of the forums, they had mentioned about creating a service and so on. But, I want to know if there is an easy way to paste it as is.
Drag/drop enters the filename, with characters that might present problems to shell scripts escaped with backslashes (such as bash). Reading the filename directly, you of course do not have this problem. The solution is to remove the extra backslashes, e.g., as done in #Ether's answer to How can I unescape backslashes in a Perl string?.
Related
I've recently updated my terminal shell to zsh on Mac OS Catalina and have found one difference from before, in which I'd prefer the previous behavior. When working in Terminal, using option arrows would move my cursor forward or backwards by one word each time. For file paths, it would move it by one directory at a time in my file path. With my update, I now see that when using this key combination with file paths in my command, instead of going directory by directory, it treats the entire file path as a single word. As I often change just parts of my file path for some repeated commands, I would like to know if anyone else had experienced this or found a workaround.
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"
I'm trying to install the Google SDK
I type:
export PYTHONPATH=$PYTHONPATH:/Users/morganallen/Dropbox/google_appengine
then:
echo $PATH
And I see:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/morganallen/Dropbox/google_appengine
But when I quit terminal and re-open it and type echo $PATH I only see:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Why isn't it saving?
I've seen other answers mentioning a .bashrc file, but I can't find mine? Not sure what to do.
If you type that into the command line, it only applies for the current session (until you close the bash window). Instead, save that line of code into your .bash_profile and it should work for every single session.
A file whose name begins with a period (.) is a hidden file. Depending on the file manager/browser which you may be using, hidden files may not be shown by default. You will need to enable viewing hidden files in the preferences/options as the case may be.
If you are using a command line to list the contents, you can use ls -a instead of plain ls.
And of course, if you need to modify the hidden file using a text editor at the command line itself, (say, using vim/nano etc.) then you can always supply the full name of the file as an argument (including the period).
shell: /bin/tcsh
I'm attempting to search for a string in a Cocos2D tmx file and replace it with text from another file.
Before the touch commands in Run Script, I have the following:
sed -i '' 's{<tileset firstgid="1.*<layer name="background"{Resources/maps_sideScrolling/tileProperties.txt{g' Resources/maps_sideScrolling/ruinsItemCave2.tmx;
I'm fairly certain the file ruinsItemCave2.tmx is found, because if I change the file path I get an error when I build the project. As of now, ruinsItemCave2.tmx is not affected in any way.
Eventually I will want to change ruinsItemCave2 to a wildcard filename so it affects every file name, though I'm not sure how to write Resources/maps_sideScrolling/*.tmx the proper way.
I also know that without even writing a file path of tileProperties.txt, but just writing "test" does nothing to my ruinsItemCave2 file, so I can't even get that far as of now. Does it have to do with using tcsh?
The batch file is something like this, I put the python in some directory that has SPACE character in its path.
C:\"Documents and Settings"\Administrator\Desktop\bracket\python\python
C:\\"Documents and Settings"\\Administrator\\Desktop\\bracket\\[10,20]\\brackettest.py
When I run this one, I get this error.
C:\Documents and Settings\Administrator\Desktop\bracket\python\python: can't ope
n file 'C:\Documents and Settings\\Administrator\\Desktop\\bracket\\[10,20]\\bra
ckettest.py': [Errno 2] No such file or directory
C:\Documents and Settings\Administrator\Desktop\bracket>
What might be wrong?
Wrapping the path doesn't solve this problem.
"C:\\Documents and Settings\\Administrator\\Desktop\\bracket\\[10,20]\\brackettest.py"
Are the brackets ('[]') cause of the problem? On Mac, python works well with bracket character.
There's no backslash escaping in the Windows console, it should read
"C:\Documents and Settings\Administrator\Desktop\bracket\python\python" "C:\Documents and Settings\Administrator\Desktop\bracket\[10,20]\brackettest.py"
Looks like you almost had it; just replace the double-slashes with single slashes.
If you're ever unsure and need a reminder of the right format. Try using the tab key to automatically complete your folder or filename. For example, at your command prompt just type:
C:\docu
then hit the tab key and it will automatically complete your folder name. From there you just type in the rest. Whenever you want to automatically complete the rest of the folder or filename, just hit the tab key. This will always produce a properly specified path that is runnable.
path = r"C:\Users\mememe\Google Drive\Programs\Python\file.csv"
Closing the path in r"string" also solved this problem very well. This tells python that it is exactly that string and avoids backslash and space errors. I use it for my files because it allows me to copy and paste directly from the navigation bar at the top of the window.
Can you
cd "\Documents and Settings"
cd "\Documents and Settings\Administrator\Desktop\bracket\python\python"
cd "\Documents and Settings\Administrator\Desktop\bracket\"
cd "\Documents and Settings\Administrator\Desktop\bracket\[10,20]\"
If all that works, do
cd "\Documents and Settings\Administrator\Desktop\bracket\python\python"
python "\Documents and Settings\Administrator\Desktop\bracket\[10,20]\brackettest.py"
Why do you have such a weird, nondescriptive dirname ([10,20])? Didn't even know that NTFS allowed that.