- What is the printed value of the following code?
#!/bin/bash
myfunc() {
arr=$1
echo "The array: ${arr[*]}"
}
my_arr=(1 2 3)
myfunc ${my_arr[*]}
- What is the output of the following code?
#!/bin/bash
myvar=50
myfunc() {
myvar=100
}
echo $myvar
myfunc
- What is the problem with the following code? And how can you fix it?
clean_file {
is_file "$1"
BEFORE=$(wc -l "$1")
echo "The file $1 starts with $BEFORE"
sed -i.bak '/^\s*#/d;/^$/d' "$1"
AFTER=$(wc -l "$1")
echo "The file $1 is now $AFTER"
}
- What is the problem with the following code? And how can you fix it?
#!/bin/bash
myfunc() {
arr=$@
echo "The array from inside the function: ${arr[*]}"
}
test_arr=(1 2 3)
echo "The origianl array is: ${test_arr[*]}"
myfunc...