Complete the code to print all files in the current directory.
for file in [1]; do echo "$file"; done
The asterisk (*) matches all files in the current directory, so the loop prints each file name.
Complete the code to check if a file named 'data.txt' exists.
if [[ [1] "data.txt" ]]; then echo "File exists"; fi
The '-e' option checks if the file exists, regardless of type.
Fix the error in the code to count lines in 'log.txt'.
count=$(cat log.txt | [1] -l)'wc -l' counts the number of lines in the input. The original code misses the command 'wc'.
Fill both blanks to create a loop that prints numbers 1 to 5.
for num in [1]; do echo [2]; done
'{1..5}' generates numbers 1 to 5. '$num' prints the current number in the loop.
Fill all three blanks to create a dictionary-like structure with file sizes.
declare -A sizes for file in [1]; do sizes[[2]]=$(stat -c [3] "$file"); done for f in "${!sizes[@]}"; do echo "$f: ${sizes[$f]} bytes"; done
'*' matches all files. 'file' is the key for the associative array. '%s' gets file size in bytes with stat.
