0

I'm trying to create a script in order to keep the files with the same extension in a folder separated from the rest. In particular, I want a script that, executed in a folder, create soft links of all .tex files and put them in a subfolder "sources".

I know that ln copes well with regular expressions, and $PWD or $(pwd) returns the path to the current folder. So I tried to execute

ln -s $PWD/*.tex ./sources/

in my folder, but soon I realized that in my path there was a folder with spaces in it, that ln reads as multiple files. So I tried with

ln -s '$PWD'/*.tex ./sources/

and

ln -s '$PWD/*.tex' ./sources/

but in both cases, the script produces a single file named *.tex in my sources folder. Following some post, I tried to modify the spaces in the path like these

ln -s $(printf "%q\n" "$PWD")/*.tex sources/

ln -s '$(printf "%q\n" "$PWD")'/*.tex sources/

ln -s '$(printf "%q\n" "$PWD")/*.tex' sources/

but the output was the same (with the difference of an additional character \).

Help?

Exodd
  • 141

1 Answers1

0

Your first attempt should work. Does it not? What does it do instead?

* substitutes with all matching filenames, but does not perform splitting at internal spaces afterwards.

"I know that ln copes well with regular expressions" – this is wrong. First, it's shell patterns that you see here, not regular expressions. Second, it's not ln coping with them but your shell (typically bash) prior to launching ln or any other command.

egmont
  • 2,566
  • 1
  • 15
  • 18