Help writing bash script
Solved/Closed
bashbabe
Posts
3
Registration date
Tuesday September 22, 2009
Status
Member
Last seen
October 25, 2009
-
Sep 22, 2009 at 08:00 PM
Stampy - Oct 5, 2009 at 08:43 AM
Stampy - Oct 5, 2009 at 08:43 AM
Hello,
I need to write a bash script that will perform the following tasks:
Create a file test.txt in the lab1 directory
If file test.txt already exists, script should inform user and create the file after deleting existing file
Change permissions of file test.txt to 755
Display exit status of the permission change command
Display contents of the lab1 directory
I am new to scripting and am practicing using the example. Any help/suggestions will be appreciated.
I need to write a bash script that will perform the following tasks:
Create a file test.txt in the lab1 directory
If file test.txt already exists, script should inform user and create the file after deleting existing file
Change permissions of file test.txt to 755
Display exit status of the permission change command
Display contents of the lab1 directory
I am new to scripting and am practicing using the example. Any help/suggestions will be appreciated.
Related:
- Help writing bash script
- Structure should be followed while writing the body of an email - Guide
- Bash reverse file - Guide
- Bash read file line by line - Guide
- Script file not found platform.resv - Windows 7 Forum
- Cannot find script file startupcheck.vbs - Viruses & Security Forum
1 response
HI there,
i am also new to bash scripting but i think it should look something like this
--------------------------------------------------------------------------------------
#!/bin/bash
#Create a file test.txt in lab1 directory
cd /??/<path to lab1>
touch text.txt
#if file exists, Inform user, Delete existing file, Create new file
if [ -f text.txt ]
then echo "File Exists"
rm text.txt
touch text.txt
fi
#change permissions of text.txt, Display exit status
chmod 755 text.txt
echo $?
#Display contents of lab1
ls
exit 0
--------------------------------------------------------------------------------------
Hope it helps/works let me know :)
Glenn
i am also new to bash scripting but i think it should look something like this
--------------------------------------------------------------------------------------
#!/bin/bash
#Create a file test.txt in lab1 directory
cd /??/<path to lab1>
touch text.txt
#if file exists, Inform user, Delete existing file, Create new file
if [ -f text.txt ]
then echo "File Exists"
rm text.txt
touch text.txt
fi
#change permissions of text.txt, Display exit status
chmod 755 text.txt
echo $?
#Display contents of lab1
ls
exit 0
--------------------------------------------------------------------------------------
Hope it helps/works let me know :)
Glenn
Oct 4, 2009 at 09:21 PM
I meant to write earlier and tell you how much I appreciated your help. It worked!
Thanks.
Bashbabe
Oct 5, 2009 at 08:43 AM
Stampy