I want to assign the path and file name to a variable:
/path/to/myfile/file.txt
For example
MYFILE=$(pwd)$(basename)
How can i do it ?
I want to assign the path and file name to a variable:
/path/to/myfile/file.txt
For example
MYFILE=$(pwd)$(basename)
How can i do it ?
To answer the question as it is stated: This is a simple string concatenation.
somedirpath='/some/path' # for example $PWD or $(pwd)
somefilepath='/the/path/to/file.txt'
newfilepath="$somedirpath"/"$( basename "$somefilepath" )"
You most likely would want to include a / between the two path elements when concatenating the strings, and basename takes an argument which is a path (this was missing in the question).
Reading your other answer, it looks like you are looking for the bash script path and name. This is available in BASH_SOURCE, which is an array. It's only element (unless you are in a function) will be what you want. In the general case, it's the last element in the array that you want to look at.
In bash 4.4, this is ${BASH_SOURCE[-1]}.
I tried this and it worked :
#!/bin/bash
SCRIPT=$(pwd)$(basename $0)
echo $SCRIPT
If there is a better way, please share.