I'm trying to get emacs to become a global name so I can reference it anywhere on my filesystem. This is what I did on the command line:
$PATH = C:/emacs/bin:$PATH
But when I do that I get the following error:
sh.exe": /c/home/bin:.:/usr/local/bin:/mingw/bin:/bin:/c/Program: No such file or directory
I even went directly to Start Menu->System [Properties]->Environment Variables and I tried to add C:\emacs\bin to the list of the paths but the name still came up as emacs: command not found. I don't know what I'm doing wrong.
Note that this is only a problem within C:\cygwin. Outside of that directory I can type emacs without a problem.
Your command
$PATH = C:/emacs/bin:$PATH
has several problems:
$ evaluates the variable, you need to set it
spaces are significant, you do not need them
you cannot use : inside a Cygwin path
Use this instead:
PATH=/c/emacs/bin:$PATH
Related
I have environment variable export MY_WORK_DIR="~/project".
While I'm using below command, it give me an error:
realpath $MY_WORK_DIR
realpath: '~/project': No such file or directory
In my guess, the ~ is not processed while using this env variable.
BTW, export MY_WORK_DIR=~/project is not an option for me. ~ should be in the string.
Could you please guide me how to get real path from envrionment variable ~/project ?
EDIT
Sorry. The variable is from other app so I cannot modify the environment variable which contains tilde. (Storing variable with tilde expanded form is not an option).
EDIT2
Is it safe to use eval command like this? eval "echo ${MY_WORK_DIR}". It works for my use.
I wouldn't use eval if I can avoid it. Especially in the way you are doing it, this is an invitation to do havoc by embedding dangerous code into MY_WORK_DIR.
A cheap solution for your concrete example would be to do a
if [[ ${MY_WORK_DIR:0:1} == '~' ]]
then
MY_WORK_DIR="$HOME/${MY_WORK_DIR:1}"
fi
which chops off the annoying ~ and prepends your home directory. But this would fail if MY_WORK_DIR is set to, say, ~einstein/project.
In this case, you would have to extract the user name (einstein) and search the home directory for this user.
Following steps can provide a resolution:
You need to replace "~" with the full path of the project directory.
Use pwd command to identify the full path of the project directory; e.g. /root/Documents/project is the full path you get.
Execute this command export MY_WORK_PROJECT=/root/Documents/project
Execute this command echo $MY_WORK_PROJECT so you should get this result
/root/Documents/project
So this is my script
#!/bin/bash
PATH=/SomeFolder/file2.txt;
scp -3 user#server1:/SomeFolder/file.txt user#server2:$PATH;
I get this error
main.sh: line 3: scp: command not found
If I put /SomeFolder/file2.txt in place of of "$PATH" it still doesn't work - same error. It's only after I remove entire second line (PATH definition) does it work.
I simplified my script, the PATH is defined by executing a script inside another server but that doesn't matter. I tested it like what you see and I concluded that the error is due to PATH being defined in the first place.
It is happening because PATH is a system variable that defines directories where the programs and scripts should be looked for. You can view its value by executing echo $PATH. In your script you are setting PATH to /SomeFolder/file2.txt so the program scp that is usually in /usr/bin/ can't be found. Just change the name of variable PATH in your script to something else.
I'm running a script called setenv.sh that sets the environment variables. One of the lines is:
config.dir=/Users/arianna/work/next/conf
After running it, I get an error message saying: config.dir=/Users/arianna/work/next/conf: No such file or directory
I'm confused because this directory exists. I can copy and paste and cd into it.
I'm befuddled here. What's wrong?
Using a . in your variable is what is causing problems; in bash it's used as an environment variable and/or only valid within certain shells which can recognize it as a regular variable. I would recommend using an underscore unless you absolutely need to use a dot.
config_dir=/Users/arianna/work/next/conf
If you want to use it as an environment variable or retrieve it then you could do:
config_dir=$( env 'config.dir=/Users/arianna/work/next/conf' \
awk 'BEGIN {print ENVIRON["config.dir"]}' )
echo "$config_dir"
Explanation:
↳ Reference to a bash variable whose name contains dot
I want to set an environment variable that has space in it. it is a path to a folder and the folder name is:
/Applications/Android Studio.app/Contents/gradle/gradle-2.10
I edit .bash_profile and add the following line to it:
export GRADLE_HOME=/Applications/Android Studio.app/Contents/gradle/gradle-2.10
and I get the result
-bash: export: `Studio.app/Contents/gradle/gradle-2.10': not a valid identifier
what should I do?
You can do it either this
export GRADLE_HOME=/Applications/Android\ Studio.app/Contents/gradle/gradle-2.10
way or this
export GRADLE_HOME="/Applications/Android Studio.app/Contents/gradle/gradle-2.10"
Important
Having taken so much pain in exporting the variable correctly, always make sure that you double quote the variable when you reference it in shell ie do:
"$GRADLE_HOME"
and not
$GRADLE_HOME
Example :
ls $GRADLE_HOME
will produce unexpected results.
I want to put my ~/Library/Application Support/ directory to a variable in my ~/.bash_profile` to make it easier to reference from within Terminal. I first attempted to define it as follows:
export L=~/Library/Application\ Support
However, when I tried to source ~/.bash_profile and then called ls $L, I got an error: /Users/username/Library/Application: Not a directory.
However, no matter how I define it I cannot define it properly, as far as I came up with the way to define it. Here's the list that I tried, but none of them worked properly.
~/Library/Application Support
"~/Library/Application Support"
"~/Library/Application\ Support"
So is it feasible to store a string which includes a whitespace to a variable in bash to begin with?
Your export statement is fine; the space is properly escaped. You just need to quote the expansion of the parameter, so that bash gives a single argument to the ls command:
ls "$L"