I am working in my Google Drive directory that is mounted on my Mac. The path to my Google Drive folder looks like: "/Users/username/Library/CloudStorage/GoogleDrive-gmail-acct/My Drive"
Notice the space between "My" and "Drive"
I am trying to run a few different codes written in C that I am passing the path of a file in my Google Drive to as an argument on the command line. I set the filename as a variable, and then pass that variable (this is in a script called "script.sh" and I run it on the command line as bash script.sh
). My shell is bash (on Mac). It looks like:
filname='/Users/username/Library/CloudStorage/GoogleDrive-gmail-acct/My Drive/myfile'
codename --filename $filname
I am getting the following error:
*Error*: cannot open /Users/<username>/Library/CloudStorage/GoogleDrive-<gmail-acct>/My
So the path is getting broken up at the space
Things I have tried:
- Using double quotes ("") around the definition of filname
- Using an escape character (backslash) before the space in definition
- Lots of combinations of those things
- Putting {} around argument, like
${filname}
and also"${filname}"
Unfortunately, I have ruled out with Google anyway to rename my Google Drive folder without a space. Does anyone know how I can handle the space since escaping it normal ways is not working?
EDIT:
I have tried the following which does not work:
script.sh
filname='/Users/username/Library/CloudStorage/GoogleDrive-gmail-acct@g.rit.edu/My Drive/file.fits'
codename "$filname"
Error:
> *Error*: cannot open /Users/username/Library/CloudStorage/GoogleDrive-gmail-acct@g.rit.edu/My
EDIT #2 with more details:
The code I am using is a code written in C that is used on the command line. I work in a very small field and the code is not public so I cannot say what it is. It is run by doing:
codename --args
specifically, I am running it in a script.sh script (with bash script.sh
) exactly as I said in my previous edit.
The path to the input file has a space in it. I think the problem is how the command line arguments are being piped into the code and are being broken by a space. To clarify, the following does work:
filname='/Users/username/Library/CloudStorage/GoogleDrive-gmail-acct@g.rit.edu/My Drive/file.fits'
echo "$filname"
but then this following does not work:
filname='/Users/username/Library/CloudStorage/GoogleDrive-gmail-acct@g.rit.edu/My Drive/file.fits'
codename "$filname"
Error:
> *Error*: cannot open /Users/username/Library/CloudStorage/GoogleDrive-gmail-acct@g.rit.edu/My
I know I really need to provide a MWE people could run themselves, and I cannot share the exact code, but I have had this exact problem with two or three other codes, all written in C and run from command line.