I’m learning Linux scripting and trying to set up a function that finds all files in the current directory. I know I could use ls but I’m wondering if there is a way to get the current directory as a command and pass it to an argument.
#!/bin/bash check_file() { for f in $1: do echo $f done } check_file pwd
This just prints out pwd:, which obviously isn’t it.
Advertisement
Answer
PWD
variable does exactly what you want.
So just replace pwd
with $PWD
and you are done