Link to home
Start Free TrialLog in
Avatar of illtbagu
illtbagu

asked on

Linux Bash Complex Variable

I would like to store a list of files as a variable using the if statement. What I have below works but its sloppy, is there a better way to do this.

#!/bin/sh
variable=
for file in /directory_path/*.txt; do
if [ -w $file ]; then file2=$file
echo $file2
fi
done
echo $variable
ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tintin
Tintin

Actually, it's probably best to use find, eg:
#!/bin/bash
variable=$(find "/directory_path/*.txt" -maxdepth 1 -type f -perm +222)

Open in new window