1 Replies - 617 Views - Last Post: 21 April 2013 - 01:40 AM Rate Topic: -----

#1 coralreef  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-April 13

UNIX Shell Scripting: If, Then Statements

Posted 18 April 2013 - 04:41 PM

I'm a beginner in UNIX shell scripting.

I'm trying to write a code where
if the user inputs a command "cat file_name.c" (file must be .c) , then it'll delete all the comments in the file_name.c, else do nothing.

So far I have this:

#!/bin/bash

read file

if [ -f "$file" ]; // trying to check if the file_name is a .c file
then
 sed '/ /,/ /d'
else               // Any other file will exit the script
 exit



Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: UNIX Shell Scripting: If, Then Statements

#2 turboscrew  Icon User is offline

  • D.I.C Addict

Reputation: 100
  • View blog
  • Posts: 628
  • Joined: 03-April 12

Re: UNIX Shell Scripting: If, Then Statements

Posted 21 April 2013 - 01:40 AM

Aren't you missing "fi" at the end of the if-block?

if [ ]; then
...
else
...
fi
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1