Question
(New to shell scripting) Now let's implement a different script called change_permission.sh. By running change_permission.sh all files with extension .txt in a specified directory (which
(New to shell scripting)
Now let's implement a different script called change_permission.sh. By running change_permission.sh all files with extension .txt in a specified directory (which you will define in the script) should have read-only permission for all users. In addition, the string "***READ ONLY***" will be appended (use >>) to each .txt file as its last line.
lets assume the directory exist(lines(folder- with some text files) and i want to change the the extension txt to read only for all user and do as it does above.
here is my change_permission.sh:
dirname=230-lab-bash-scripts
extension=.txt
$dirname
counter=0
sourcefile=aladdin.txt
for i in extension; do
chmod ug = r change_permission.sh (i tried looking up the man for chmod and i dont know if i am using it right)
filename="$dirname""/""$(printf %03d $counter)""$extension">>"$ug"
echo "$line" > $filename
((++counter))
done
as for split.sh:
#!/bin/bash
# The first line of the script indicates what program is to be used to interpret
# the script. In this case, /bin/bash.
# Everything that appears after a "#" symbol is ignored by bash.
# To create a variable, put a line in the script that contains the name of the
# variable followed immediately by an equal sign ("="). NO SPACES are allowed.
# After the equal sign, assign the information to store.
# The only characters allowed in variable names are [A-Za-z0-9_] (alphanumeric
# characters and underscore).
dirname=lines
extension=.txt
rm -rf $dirname
# Whenever the shell sees a word that begins with a "$", it tries to find out
# what was assigned to the variable and substitutes it.
mkdir $dirname
sourcefile=aladdin.txt
counter=0
# Check the man page of read for its usage
while IFS= read -r line; do
filename="$dirname""/""$(printf %03d $counter)""$extension" # concatenate strings
echo "$line" > $filename
((++counter))
done
230-LAB-BASH-SCRIPTS [SSH:... [ D 0 0 > lines aladdin.txt change_permission.sh README.md split.sh 230-LAB-BASH-SCRIPTS [SSH:... [ D 0 0 > lines aladdin.txt change_permission.sh README.md split.sh
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started