cp -R "~/photo dir" /backups #method1 cp -R ~"/photo dir" /backups #method2 cp -R ~/"photo dir" /backups #method3
"$HOME/photo dir"
will be successful."~/"
to the user's home directory and then append the quoted directory name that includes a space."~/"
to the user's home directory and then append the quoted directory name that includes a space."~/"
to the user's home directory and then append the quoted directory name that includes a space.$ ls -1 Beach photo1.jpg Photo1.jpg Photo2.jpg Script.sh $ cat script.sh for i in $(ls *.jpg); do mv $i ${i}.bak done
( command )
sh command
{ command; }
(( command ))
echo "1 2 3" | awk '{for (i=1; i<=NF; i++) s=s+$i};END {print s}'
find / -name "finance.db" 1>results.txt 2>/dev/null
sed -i '/^$/d' textfile
sed '/^$/d' textfile
cat textfile | sed '/^$/d
sed -i 's/^$//' textfile
awk -F: '/user1/{print $1 "-" $3 "-" $6}' /etc/passwd
"set -e"
in a Bash script?mysql < file.sql > file.txt
cat {$1,textfile}
cat textfile | awk [print $1]
cat textfile | awk '{print $1}'
awk textfile {print $1}
(reverse-i-search)`':
var=$( expr 10 / 8 )
(( var= 10 /8 ))
var=$(( 10 / 8 ))
var=$(echo 'scale=2; 10 / 8' | bc)
txt=Penguins [[ $txt =~ [a-z]{8} ]]; echo $?
HAL>
SHELL="HAL\>"
SHELL="HAL>"
export PS1="HAL>"
PS1="HAL\>"
VAR="/var/www/html/website.com/html/" echo "${VAR#*/html}"
/website.com/html/
/html/website.com/html/
/var/www/html/website.com/
#!/usr/bin/env bash
~/usr/bin/env bash
'$!/usr/bin/env bash
#/usr/bin/env bash
The date is: Sun Mar 24 12:30:06 CST 2019!
echo "The date is: !"
echo "The date is: date!"
echo "The date is: (date)!"
echo "The date is: $(date)!"
A. /home/demo.sh B. ./demo.sh C. ~/demo.sh D. bash /home/demo.sh E. bash demo.sh
find . -type html
find . -name *.html
find *.html
find . -name \*.html -print
cat < in.txt > out.txt
(( $a == $b )) echo $?
$a
and $b
.$a
and $b
are equal.$b
if it is larger than $a
.$a
if it is larger than $b
.; ;
: :
done
$$
<em>#!/usr/bin/env bash</em> case $num in 1) echo "one" ; ; 2) echo "two" ; ; *) echo "a mystery" ; ; esac
touch file{1+10}.txt
touch file{1-10}.txt
touch file{1..10}.txt
touch file(1..10).txt
$$
$?
$!
$@
Start from this question and to Q40 I have a lot of doubts about answers
because in real assessment I get these 12 question + 3 from Q1 to Q28,
and I select other answers in Q29, Q31, Q32, Q35, Q36, Q37, Q39, Q40 and pass it
#!/bin/bash fname=john john=thomas echo ${!fname}
john
thomas
Syntax error
blank
A
B
C
D
Here a text based version of Q.30:
ll -rw-r--r-- 1 frankmolev staff 374 Jun 3 19:30 . -rw-r--r-- 1 frankmolev staff 1666 Jun 3 19:30 .. -rw-r--r-- 1 frankmolev staff 0 Jun 3 19:30 file1.txt -rw-r--r-- 1 frankmolev staff 0 Jun 3 19:30 file2.txt .. ll | sed -e 's,file,text,g'
-rw-r--r-- 1 frankmolev staff 374 Jun 3 19:30 .
-rw-r--r-- 1 frankmolev staff 1666 Jun 3 19:30 ..
-rw-r--r-- 1 frankmolev staff 0 Jun 3 19:30 file1.file
-rw-r--r-- 1 frankmolev staff 0 Jun 3 19:30 file2.file
..
-rw-r--r-- 1 frankmolev staff 374 Jun 3 19:30 .
-rw-r--r-- 1 frankmolev staff 1666 Jun 3 19:30 ..
-rw-r--r-- 1 frankmolev staff 0 Jun 3 19:30 file1.txt
-rw-r--r-- 1 frankmolev staff 0 Jun 3 19:30 file2.txt
..
-rw-r--r-- 1 frankmolev staff 68 Jun 3 19:30 .
-rw-r--r-- 1 frankmolev staff 1666 Jun 3 19:30 ..
-rw-r--r-- 1 frankmolev staff 374 Jun 3 19:30 .
-rw-r--r-- 1 frankmolev staff 1666 Jun 3 19:30 ..
-rw-r--r-- 1 frankmolev staff 0 Jun 3 19:30 text1.txt
-rw-r--r-- 1 frankmolev staff 0 Jun 3 19:30 text.txt
..
#!/bin/bash read -p "Enter your pet type." PET if [ $PET = dog ] ;then echo "You have a dog" fi
If the value of PET doesn't match dog, the script will return a nonzero status code.
There is nothing wrong with it. The condition checks the value of PET perfectly.
It will fail if the user hits the Enter (Return) key without entering a pet name when prompted.
The then statement needs to be on a separate line.
It just works by default.
history --shared
history --combined
shopt -s histappend
$@ treats each quoted argument as a separate entity. $* treats the entire argument string as one entity.
$* treats each quoted argument as a separate entity. $@ treats the entire argument string as one entity.
$* is used to count the arguments passed to a script, $@ provides all arguments in one string.
$* is the wildcard that includes all arguments with word splitting, $@ holds the same data but in an array.
if [ -f file.txt ]; then echo "file.txt exists" fi
/usr/bin/test
/usr/bin/[
the built-in [ command
/usr/bin/[[
#!/bin/bash Linux=('Debian' 'Redhat' 'Ubuntu' 'Android' 'Fedora' 'Suse') x=3 Linux=(${Linux[@]:0:$x} ${Linux[@]:$(($x + 1))}) echo "${Linux[@]}"
Debian Redhat Ubuntu Android Fedora Suse
Android
Fedora Suse
Debian Redhat Ubuntu Fedora Suse
/etc/bash.conf
~/.profile
/etc/bashprofile
~/profile
$ ls -l
total 0
-rwx------+ 1 user1 user1 0 Oct 27 10:54 data.txt
No, it's clear that user2 does not have read, write, and execute permissions.
Yes, the + at the end of the 10-digit permission string signifies there's an access control list. This could possibly give user2 permissions not visible by ls -l.
It's possible that SELinux provides read, write, and execute permissions for user2 which are not visible with ls -l.
Yes, the + at the end of the 10-digit permission string signifies there's an extended attribute set. This could give user2 permissions to read, write, and execute data.txt.
#!/bin/bash declare -A ARRAY=([user1]=bob [user2]=ted [user3]=sally) KEYS=(${!ARRAY[@]}) for (( i=0; $i < ${#ARRAY[@]}; i+=1 ));do echo ${KEYS[$i]} - ${ARRAY[${KEYS[$i]}]} done
It sorts the associative array named ARRAY and stores the results in an indexed array named KEYS. It then uses this sorted array to loop through the associative array ARRAY.
Using a C-style for loop, it loops through the associative array named ARRAY using the associative array's keys and outputs both the key and values for each item.
It creates an indexed array of the associative array named ARRAY. It then uses a C-style for loop and the indexed array to loop through all items in the associative array, outputting the key and value of each array item using the index number.
It creates an associative array named ARRAY, which it loops through using a C-style for loop and the index numbers of each item in the associative array's keys, outputting the value of each item.
ls Hello[[.vertical-line.]]World
It's matches also Hello[[.vertical-line.]]World
file but if we have this and Hello|World
file will always be matched last one
Nothing, this is an invalid file glob.
Hello.vertical-line.World
Hello[[.vertical-line.]]World
Hello|World
ls nonexistentfile | grep "No such file" > out.txt
No such file
ls: cannot access nonexistentfile: No such file or directory
Nothing, out.txt will be empty.
It will be the contents of nonexistentfile.
#!/bin/bash read -p "Enter text " var if [[ "$var" =~ "^[0-9]+$" ]];then echo "Is numeric" else echo "Is not numeric" fi
^[0-9]]+$
Only this will prove to be true and "Is numeric" would be printed on the screen due to incorrect syntax. By encapsulating the regular expression in double quotes every match will fail except the text string ^[0-9]+$
mysql < file.sql > out.txt
bash for i in $(ls); do ... done
bash for $(ls); do ... done
bash for i in $ls; do ... done
bash for $ls; do ... done
<em>#!/usr/bin/env bash</em> greeting="Hello" echo $greeting, everybody!
$ ls -l apple banana bananapple banapple pineapple strawberry $ shopt -s extglob $ ls -l @(ba*(na)|a+(p)le)
apple banana
apple banana bananapple banapple pineapple strawberry
apple banana bananappple banapple pineapple
apple banana bananapple banapple pineapple
ls -l
-rwx------+ 1 user1 u1 0 Oct 1 10:00 data.txt
Training questions
cat > notes -
VAR="This old man came rolling" echo "\${VAR//man/rolling}"