Results 1 to 4 of 4
Hello, I'm new in linux, please help me to write this shell script and explain them
1- Write a shell script (trans.sh) that :
- Take as command-line options any ...
- 02-22-2009 #1Just Joined!
- Join Date
- Feb 2009
- Posts
- 3
please help me to write this shell script
Hello, I'm new in linux, please help me to write this shell script and explain them
1- Write a shell script (trans.sh) that :
- Take as command-line options any number of text files
-Read in each of these files, converts all the letters to uppercase, and then stores the results in a file of the same name but with a .caps extension
2- Write a script (execadd.sh) that will take a single filename as an argument and adds execute permission to the file for the user, but only if the file is a regular file.
Your script must check to see that there is exactly one argument. If there are no arguments or more than one arguments, your script must produce a "usage" message that tells how to use the script.
- 02-26-2009 #2Linux Newbie
- Join Date
- Feb 2009
- Posts
- 99
1.
#!/bin/bash
file=`ls -l | awk '{print $NF}'
for name in $file
do
wc 'a-z''A-Z' $name.caps < $name
done
2. I don't know your meaning .. ^__^
maybe your mean is :
file1 file2 file3 fie4
and execute ---> execadd.sh file1 <-- then execute argument file1 as one execute file ?
so --> try
#!/bin/bash
if [ $* -ne 1 ]
then
echo "usage: execadd.sh filename"
exit 1
fi
ls $1
if [ $? -ne 0 ]
then
echo "usage is execadd.sh fielname"
else
source ./$!
fi
- 03-02-2009 #3Just Joined!
- Join Date
- Feb 2009
- Posts
- 3
thank u
dear,
Here is the result of running the script several times, with extra
blank lines to make things more readable.
linux199@linux:~> touch file1
linux199@linux:~> mkdir dir1
linux199@linux:~> ./addexec.sh
Usage: ./addexec.sh filename
linux199@linux:~> ./addexec.sh file1 file2
Usage: ./addexec.sh filename
linux199@linux:~> ./addexec.sh dir1
dir1 is not a regular file.
linux199@linux:~> ./addexec.sh nosuchfile
nosuchfile does not exist.
linux199@linux:~> ls -l file1
-rw-r--r-- 1 linux199 users 0 2006-11-21 17:38 file1
linux199@linux:~> ./addexec.sh file1
linux199@linux:~> ls -l file1
-rwxr--r-- 1 linux199 users 0 2006-11-21 17:38 file1
i'm trying this sicrpt but there are still errors
#!bin/shell
#Tarek_20307
#Exercise 4:
if [$# -eq 0]
then
echo ""
echo "error: you didn't entered a file nameafter script"
echo ""
exit 1
fi
if [$# -gt 1]
then
echo "error: you entered 2 files name or more"
echo "right syntax: ./execadd.sh file-name"
exit 1
fi
if [$# -eq 1] && ls | grep= $1
then
sudo chmod 755 $1
echo "you have permission now on $1"
else
echo "file doesn't exict in this directory"
exit 0
fi
- 03-16-2009 #4Just Joined!
- Join Date
- Feb 2009
- Posts
- 3
Help me
please help meto fix the problem with this script:
Write a script (execadd.sh) that will take a single filename as an argument and adds execute permission to the file for the user, but only if the file is a regular file.
Your script must check to see that there is exactly one argument. If there are no arguments or more than one arguments, your script must produce a "usage" message that tells how to use the script.
Here is the result of running the script several times, with extra
blank lines to make things more readable.
linux199@linux:~> touch file1
linux199@linux:~> mkdir dir1
linux199@linux:~> ./addexec.sh
Usage: ./addexec.sh filename
linux199@linux:~> ./addexec.sh file1 file2
Usage: ./addexec.sh filename
linux199@linux:~> ./addexec.sh dir1
dir1 is not a regular file.
linux199@linux:~> ./addexec.sh nosuchfile
nosuchfile does not exist.
linux199@linux:~> ls -l file1
-rw-r--r-- 1 linux199 users 0 2006-11-21 17:38 file1
linux199@linux:~> ./addexec.sh file1
linux199@linux:~> ls -l file1
-rwxr--r-- 1 linux199 users 0 2006-11-21 17:38 file1
this is my trying
#!/bin/sh
If [$# -ne 1] # check if number of argument is not equal to 1
Then
Echo “Usage: $0 filename” # giving a Usage Message
Elif [$# == 1] # check if number of argument is equal to 1
Then
If $1 –f # checking if file is existed
Then
chmod 775 $1
# Adding execute permission to make file readable and executable by others, but only changeable by the issuing user.
Else
Echo “file isn’t a regular file”
Fi
Else
Echo “error: file does not exist” # giving a Error Message
Exit 0
Fi


Reply With Quote