0

I usualy combine some file PDF to one file PDF and put name with today date. This code:

#get today's date
export LANG=id_ID
export TZ=Asia/Jakarta
TODAY=$(date --date='0 days' '+%Y%m%d')

#combine and name file
pdftk *.pdf cat output document"$TODAY".pdf

Now, I want change TODAY with CURRENT FOLDER NAME (ex. folder name: Full01). I get this code for current folder name:

echo "${PWD##*/}"

or:

printf '%s\n' "${PWD##*/}"

How do I use the code? Can anyone help?

PUSTAKAKORAN.COM
  • 455
  • 1
  • 5
  • 18
  • soo `TODAY=$(echo ...)` ? – KamilCuk Sep 08 '21 at 07:16
  • I've tried several combinations of existing code, all not working. Haven't found any code that works properly. – PUSTAKAKORAN.COM Sep 08 '21 at 07:31
  • `all not working` What does it mean "not working"? How do you check it? `that works properly` What does it mean to "work properly"? How do you check it? – KamilCuk Sep 08 '21 at 07:46
  • @PUSTAKAKORAN.COM : _ I want change TODAY with CURRENT FOLDER NAME_ ... What does it mean to **change** a variable **with** a name? Perhaps it would help if you show with an example the desired effect. – user1934428 Sep 08 '21 at 08:11

2 Answers2

1

I have tried the following code:

here=${PWD##*/}
echo $here

This is working fine.

What have you tried and what errors do you get?

Dominique
  • 16,450
  • 15
  • 56
  • 112
0

Try this:

current_folder_name=$(basename "$(readlink -f .)")
ceving
  • 21,900
  • 13
  • 104
  • 178
  • Thanks for ceving. I've tried the code, but it doesn't work either. – PUSTAKAKORAN.COM Sep 08 '21 at 07:41
  • @PUSTAKAKORAN.COM I have no idea what is not working. You just asked how to get the current folder name. And the above line does it and it works. – ceving Sep 08 '21 at 07:48
  • The code provided is correct and can take the name for the current folder. But when put to give a name to the file, the code doesn't say the folder name, but it says "current_folder_name" – PUSTAKAKORAN.COM Sep 08 '21 at 07:55
  • Put a `$` in front. And maybe read a beginners tutorial about shell scripting. – ceving Sep 08 '21 at 07:56
  • I use code: pdftk *.pdf cat output document"$current_folder_name".pdf. The resulting filename should be documentNAME-FOLDER.pdf, but it will be document$current_folder_name.pdf – PUSTAKAKORAN.COM Sep 08 '21 at 08:13
  • Maybe you use [single quotes instead of double quotes](https://stackoverflow.com/questions/6697753/difference-between-single-and-double-quotes-in-bash). – ceving Sep 08 '21 at 08:47