d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Need Help With Script In Linux
12Next
Add Reply New Topic New Poll
Member
Posts: 27,086
Joined: Mar 7 2008
Gold: 685.00
Mar 21 2014 02:54pm
User have to choose 2 options: 1 to show file access of a file or 2 for his contents. For both, we have to specify file name and make sure the file exists.

For option 1 : Display in numeric and text file access like : File.txt Acess= 0741 (RWX R-- --X)

For option 2: Display the Tag "File content" + $FileName and for the next lines, content of the file with #line



questions?
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Mar 21 2014 05:23pm
Quote (eric838 @ Mar 21 2014 03:54pm)

questions?


The only question I have is, "what is your question?"

Member
Posts: 27,086
Joined: Mar 7 2008
Gold: 685.00
Mar 21 2014 07:09pm
Quote (Minkomonster @ 21 Mar 2014 18:23)
The only question I have is, "what is your question?"


the quastion is that I need help 4 this
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Mar 21 2014 07:36pm
Quote (eric838 @ Mar 21 2014 08:09pm)
the quastion is that I need help 4 this


Again, what is your question? What exactly don't you understand?
Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
Mar 21 2014 07:53pm
I know you know what you are trying to say, but we don't have access to that. We only have access to what you have actually said, so please try to rephrase it, with more detail.
Member
Posts: 27,086
Joined: Mar 7 2008
Gold: 685.00
Mar 21 2014 08:06pm
Code
echo "Choose between those 2 options:"
echo "1. Display file acces of a file"
echo "2. Display content of a file"
read choice
while !["$choice" = "1"] && !["$choice" = "2"]; do
read choice
echo "Choose between those 2 options:"
echo "1. Display file acces of a file"
echo "2. Display content of a file"
done

echo "Select file name" #must be typed
read FileName
if ["$FileNAme" exists]; then #dont know how to check if the typed file exists in current directory must check 4 this
if ["$choice" = "1"];then
#display file acess like this : File.txt Acess= 0741 (RWX R-- --X)
elif ["$choice" = "2"]; then
#display content of the file displaying line #
fi
fi


that could help a lil bit



This post was edited by eric838 on Mar 21 2014 08:15pm
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Mar 21 2014 08:40pm
Quote (eric838 @ Mar 21 2014 09:06pm)
Code
echo "Choose between those 2 options:"
echo "1. Display file acces of a file"
echo "2. Display content of a file"
read choice
while !["$choice" = "1"] && !["$choice" = "2"]; do
        read choice
  echo "Choose between those 2 options:"
  echo "1. Display file acces of a file"
  echo "2. Display content of a file"
done

echo "Select file name"              #must be typed
read FileName
if ["$FileNAme" exists]; then  #dont know how to check if the typed file exists in current directory must check 4 this
          if  ["$choice" = "1"];then
                    #display file acess like this : File.txt Acess= 0741 (RWX R-- --X)
          elif ["$choice" = "2"]; then
                    #display content of the file displaying line #
          fi
fi


that could help a lil bit



To check if a file exists you can do

Code
if[ -e "$FileName" ];
then #file found
else #file not found
fi



To display the contents of a file with line numbers you can do

Code
cat -n $FileName


I am unsure what you mean by file access though. Perhaps I am jsut an idiot and am missing something simple though...
Member
Posts: 27,086
Joined: Mar 7 2008
Gold: 685.00
Mar 21 2014 08:45pm
Quote (Minkomonster @ 21 Mar 2014 21:40)
To check if a file exists you can do

Code
if[ -e "$FileName" ];
then #file found
else  #file not found
fi



To display the contents of a file with line numbers you can do

Code
cat -n $FileName


I am unsure what you mean by file access though. Perhaps I am jsut an idiot and am missing something simple though...



u can see it with " ls -l" I think and its what you can modidy with "chmod" what I mean with acess is user/group/other with read/write/execute


btw trying to do a do...while loop like c language but idk how

in C++ that would be :


Code
do
{
cout << "Choose between those 2 options:" <<endl;
cout << "1. Display file acces of a file" << endl;
cout << "2. Display content of a file" << endl;
cin >> choice;
}
while (choice != 1 && choice != 2 );


This post was edited by eric838 on Mar 21 2014 08:57pm
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Mar 21 2014 08:47pm
Quote (eric838 @ Mar 21 2014 09:45pm)
u can see it with  " ls -l" I think and its what you can modidy with "chmod"  what I mean with acess is    user/group/other  with read/write/execute


ah, yes ok, duh

Code
ls -l $FileName
Member
Posts: 11,610
Joined: Oct 28 2008
Gold: 1,795.00
Mar 22 2014 08:13am
If you're wanting this clean like what is required of you

Code
$ ls -lah dump.sql | awk '{print "Perms: " $1}'
>> Perms: -rw-r--r--
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll