Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting current directory in linux for argument

Tags:

linux

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.

like image 939
jumbopap Avatar asked Nov 30 '22 20:11

jumbopap


1 Answers

PWD variable does exactly what you want. So just replace pwd with $PWD and you are done

like image 84
sasha.sochka Avatar answered Dec 04 '22 12:12

sasha.sochka