LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-08-2012, 09:16 AM   #1
Lindy70
LQ Newbie
 
Registered: May 2012
Posts: 3

Rep: Reputation: Disabled
Exclamation Script, display contents of a file using cat


This is the script I'm working on, I'm finished except for "displaying a file using cat" I'm unsure of the "wording". I know it's
Code:
cat filename
to view a file. I tried doing
Code:
echo "Enter a filename"
     cat $fname
     more $fname
I can't figure out what I missing.
I'm new to all of this and still tying too figure out all the commands. I would appreciate any insight you can give me.








Code:
#!/bin/bash
  leave=no
  while [ $leave = no ]
  do
echo Hello $USER
  cat <<++


          MAIN MENU
 1)  Print current working directory
 2)  Delete a file
 3)  Rename a file
 4)  List all files in a current directory
 5)  Display contents of a file
 6)  Edit a file
 7)  Copy a file
 8)  Move a file
 x)  Exit
++

  echo Please enter your selection $LOGNAME:
  read selection
  case $selection in
  1) pwd;;
  2) echo "Enter any $filename to be deleted"
     read f1
        rm $f1
          echo $f1" is deleted";;
  3) echo "Enter file to to rename"
     read f1
     echo "Enter new name of file"
     read f2
          mv $f1 $f2
           echo $f1" is renamed as "$f2;;
  4) ls -l;;
  5) echo "Enter a filename"
     read $fname
     more $fname
     ;;
  6) echo "enter any file to be edited"
      read f1
            vi $f1;;
  7) echo "Enter $filename to copy"
     read f1
     echo "Enter filename2 to be copied"
     read f2
             #cat $f1 > $f2
                cp $f1 f2
                 echo $f2" is copied from "$f1;;
  8) echo "Enter $filename to move"
     read f1
     echo "Enter filename2 where to be moved"
     read f2
          mv $f1 $f2
        echo $f1" has been moved";;
  x) exit;;
  esac
  done
  Exit 0
 
Old 05-08-2012, 09:36 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
The problem is the script asks the user to enter the file name but does not read what the user enters. The shell's read command would be useful.
 
Old 05-08-2012, 10:13 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,976

Rep: Reputation: 3181Reputation: 3181Reputation: 3181Reputation: 3181Reputation: 3181Reputation: 3181Reputation: 3181Reputation: 3181Reputation: 3181Reputation: 3181Reputation: 3181
As I assume this is homework which is to be marked, may I suggest you try entering a space separated file name for any of your examples and see how your output goes.

Also, you seem to have great trust in your user as you never check that they give you a valid file name, ie. does it exist? can you do the things you want to, to the file?

Just food for thought
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
File manager that read scripts that determine how to display a folder contents. pirriperdos Linux - Software 1 01-17-2012 02:48 AM
display contents of file gr8linux Linux - Newbie 8 07-08-2009 05:36 PM
how to display text file contents in Xdialog's radiolist or menubox kkpal Linux - Newbie 0 09-09-2008 02:18 AM
Display file contents in table format dresch Linux - Newbie 1 01-04-2007 09:35 AM
Apache2: How to allow Apache to display contents in the file system? vous Linux - Software 1 02-03-2004 05:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration