Getting current path in variable and using it
myvar="$PWD"
cd "$myvar"
(Quotes are necessary if your path contains whitespaces.)
Save current directory in variable using Bash?
This saves the absolute path of the current working directory to the variable cwd
:
cwd=$(pwd)
In your case you can just do:
export PATH=$PATH:$(pwd)+somethingelse
Windows shell command to get the full path to the current directory?
Use cd
with no arguments if you're using the shell directly, or %cd%
if you want to use it in a batch file (it behaves like an environment variable).
How to store current directory path in variable from bash script for windows?
Assuming you're really in bash:
mkdir upload
cd upload
DB_IMG_PATH=$PWD
echo "$DB_IMG_PATH"
cd ..
echo '{"public":{"imgUploadUrl":"'"$DB_IMAGE_PATH"'","adminUser":"admin@mitch.org","adminPassword":"admin@123"}}' >> settings.json
And the same thing without unnecessary cd steps:
mkdir upload
DB_IMG_PATH=$PWD/upload
echo "$DB_IMG_PATH"
Please be aware though:
- By convention, we capitalize environment variables (PAGER, EDITOR, ..) and internal shell variables (SHELL, BASH_VERSION, ..). All other variable names should be lower case. Remember that variable names are case-sensitive; this convention avoids accidentally overriding environmental and internal variables.
- Never change directories in a script unless you check if it failed!
cd $foo
is bad.cd "$foo" || exit
is good.
batch script to set a variable with the current path location
The current directory is in the "shadow" variable cd.
You could try
set "var=%cd%"
In Python Use Current Directory as variable
You have:
dir = os.getcwd()
timeStamp = datetime.datetime.now().strftime("%A, %d. %B %Y %I-%M%p")
os.path.join('/dir', 'video_'+timeStamp+'_.mov')
and seem to be puzzled as to why you are getting something like /dir/video…
out of the os.path.join(). You have quoted /dir
so are literally getting '/dir'
in your pathname. If you instead used:
os.path.join(dir, 'video…')
Youd get the cwd concatenated with the rest of the file name.
What is the current directory in a batch file?
From within your batch file:
%cd%
refers to the current working directory (variable)%~dp0
refers to the full path to the batch file's directory (static)%~dpnx0
and%~f0
both refer to the full path to the batch directory and file name (static).
See also: What does %~dp0 mean, and how does it work?
Related Topics
Using Curl in a Bash Script and Getting Curl: (3) Illegal Characters Found in Url
How Does Copy_From_User from the Linux Kernel Work Internally
Branch-Specific Configuration File Maintenance with Git
Pytorch Says That Cuda Is Not Available
Building a Simple (Hello-World-Esque) Example of Using Ld's Option -Rpath with $Origin
How to Send Multicast Packets via a Specfic Interface in Linux
How to Give Highest Priority to Ethernet Interrupt in Linux
Does Madvise(_, _, Madv_Dontneed) Instruct the Os to Lazily Write to Disk
Dynamically Determining Where a Rogue Avx-512 Instruction Is Executing
How to Forward Localhost Port on My Container to Localhost on My Host
How to Add Chromedriver to Path in Linux
Linux Command to Delete All Files Except .Git Folder
How to Pass a Value to a Builtin Linux Kernel Module at Boot Time
Compiling Out-Of-Tree Kernel Module Against Any Kernel Source Tree on the Filesystem
Perf Stat Does Not Count Memory-Loads But Counts Memory-Stores