LinuxQuestions.org
Help answer threads with 0 replies.
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 07-14-2017, 03:13 PM   #1
Abdulmalek97
LQ Newbie
 
Registered: Jul 2017
Posts: 19

Rep: Reputation: Disabled
some obstacles in executing commands and having limited permission to some files


I am learning the commands and it is going great. This is an obstacle which I could not figure it out from other forums and online. trying to learn chmod command by doing the following

problem number 1:
1-I can't execute test.sh after doing the following.

echo "shit happens" > test

chmod +x test.sh

./test.sh

I am getting

./test.sh: line 1: shit: command not found

Any ideas?

2- on the other files, it says permission denied. I watched some Youtube tutorials and applied them, still won't work. (to be specific, I changed the ownership of the file to root)
and if I enter # ls -ld , I get this:

drwxr-xr-x 22 root root 4096 Feb 20 2005 /

which seems fine to me but will still get permission denied

Thnx in advance

N.B: using Kali Linux
Attached Thumbnails
Click image for larger version

Name:	wwwwwwwwwwwww.jpg
Views:	8
Size:	80.3 KB
ID:	25467  

Last edited by Abdulmalek97; 07-14-2017 at 04:12 PM.
 
Old 07-14-2017, 03:35 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,505

Rep: Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113
An executable file is not the same thing as a file that is executable. Changing the permissions on a file that contains random text does not create an executable program. A bash script is taking all those commands you have been learning and putting them into a file to have some sort of automated process. There are many guides and tutorials on bash scripting.

http://tldp.org/LDP/Bash-Beginners-Guide/html/
 
Old 07-14-2017, 03:40 PM   #3
Abdulmalek97
LQ Newbie
 
Registered: Jul 2017
Posts: 19

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
An executable file is not the same thing as a file that is executable. Changing the permissions on a file that contains random text does not create an executable program. A bash script is taking all those commands you have been learning and putting them into a file to have some sort of automated process. There are many guides and tutorials on bash scripting.

http://tldp.org/LDP/Bash-Beginners-Guide/html/
hmmm. Not sure what the problem in my case was. Can you provide some more demonstration?
 
Old 07-14-2017, 03:58 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,505

Rep: Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113
An actual program contains commands that follow a particular language syntax. Your file does not which is why you see the error code despite the fact that it is executable.

Put the following lines in a text file and change its permissions so that it is executable. See what happens when you execute the file.

Code:
#!/bin/bash
echo "Hello, World!"
 
Old 07-14-2017, 04:17 PM   #5
Abdulmalek97
LQ Newbie
 
Registered: Jul 2017
Posts: 19

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
An actual program contains commands that follow a particular language syntax. Your file does not which is why you see the error code despite the fact that it is executable.

Put the following lines in a text file and change its permissions so that it is executable. See what happens when you execute the file.

Code:
#!/bin/bash
echo "Hello, World!"
what did i do wrong here?
Attached Thumbnails
Click image for larger version

Name:	wwwwwwwwwwwww.jpg
Views:	5
Size:	59.1 KB
ID:	25468  
 
Old 07-14-2017, 04:21 PM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,505

Rep: Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113
Use a text editor and copy/paste the provided code.

The echo command as posted creates a text file that contains hello world which is not the same as the above code.
 
Old 07-14-2017, 04:23 PM   #7
Abdulmalek97
LQ Newbie
 
Registered: Jul 2017
Posts: 19

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
Use a text editor and copy/paste the provided code.

The echo command as posted creates a text file that contains hello world which is not the same as the above code.
but you asked me to put hello world in a txt file, right? cause if I only have echo hello world, it will print it on the terminal and that is not what i was trying to achieve.
 
Old 07-14-2017, 04:30 PM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,505

Rep: Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113
Quote:
but you asked me to put hello world in a txt file, right? cause if I only have echo hello world, it will print it on the terminal and that is not what i was trying to achieve.
Not in the context of creating a script that you can execute.
 
Old 07-14-2017, 04:31 PM   #9
Abdulmalek97
LQ Newbie
 
Registered: Jul 2017
Posts: 19

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
Not in the context of creating a script that you can execute.
i am sorry. I don't seem to understand. there must be a miscommunication.

Last edited by Abdulmalek97; 07-14-2017 at 05:03 PM.
 
Old 07-14-2017, 04:38 PM   #10
Abdulmalek97
LQ Newbie
 
Registered: Jul 2017
Posts: 19

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
Not in the context of creating a script that you can execute.
This is the tutorial that I am trying to achieve but I get the error and he obviously doesn't. I am wondering what did I do differently because i am literally following his words and in all the other commands, it went well.

edit: video is uploading.....

Last edited by Abdulmalek97; 07-14-2017 at 05:03 PM.
 
Old 07-14-2017, 04:44 PM   #11
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,505

Rep: Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113
Yes there seems to be some miscommunication.. Type in these commands exactly
Code:
echo '#!/bin/bash' > test.sh
echo 'echo "Hello World"' >> test.sh
chmod +x test.sh
./test.sh
 
2 members found this post helpful.
Old 07-14-2017, 04:49 PM   #12
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,620
Blog Entries: 11

Rep: Reputation: 3657Reputation: 3657Reputation: 3657Reputation: 3657Reputation: 3657Reputation: 3657Reputation: 3657Reputation: 3657Reputation: 3657Reputation: 3657Reputation: 3657
Quote:
Originally Posted by Abdulmalek97 View Post
i am sorry. I don't seem to understand. there must be a miscommunication. I will record a video of what I am trying to do> give me 5 minutes please.
I would discourage your from using video as a primary means of communicating your tasks, code and data as it is more difficult for others to understand your questions and problems and creates a huge obstacle to your learning experience in my opinion. Particularly in something as simple and basic as shell scripting, it is simply not an appropriate medium.

It is clear that you have not yet grasped the most basic concept of shell scripting and programming, that of passing arguments to some function for processing. In this case, passing a string to the echo function for writing to the screen. This has nothing to do with permissions on the file itself.

Michaelk has posted a link to one of the best resources available for learning those concepts, please try to work your way through the examples it contains. Until you do, you will not be able to learn any other concepts.

Additionally, you might want to look at the Advanced Bash Scripting Guide and the Rute User's Tutorial and Exposition.

I would also urge you to try another distro for your learning experience. Kali Linux is specifically designed for Linux and networking experts and is really unsuitable for learning the basics - even dangerous to yourself and others in unknowledgable hands.
 
1 members found this post helpful.
Old 07-14-2017, 05:01 PM   #13
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,505

Rep: Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113Reputation: 4113
The OP is following an ethical hacking course. I agree that some basic skills are required which might be better learned on a "normal" distribution.
 
1 members found this post helpful.
Old 07-14-2017, 05:02 PM   #14
Abdulmalek97
LQ Newbie
 
Registered: Jul 2017
Posts: 19

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
Yes there seems to be some miscommunication.. Type in these commands exactly
Code:
echo '#!/bin/bash' > test.sh
echo 'echo "Hello World"' >> test.sh
chmod +x test.shry
./test.sh
you are a genius .

Thanks. It worked. What is the trick and what is the story with all these echos and double writing it? in the video, he didn't do it like that and still worked. there was no bin bash and stuff. but there was indeed two echos
 
Old 07-14-2017, 05:06 PM   #15
Abdulmalek97
LQ Newbie
 
Registered: Jul 2017
Posts: 19

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by astrogeek View Post
I would discourage your from using video as a primary means of communicating your tasks, code and data as it is more difficult for others to understand your questions and problems and creates a huge obstacle to your learning experience in my opinion. Particularly in something as simple and basic as shell scripting, it is simply not an appropriate medium.

It is clear that you have not yet grasped the most basic concept of shell scripting and programming, that of passing arguments to some function for processing. In this case, passing a string to the echo function for writing to the screen. This has nothing to do with permissions on the file itself.

Michaelk has posted a link to one of the best resources available for learning those concepts, please try to work your way through the examples it contains. Until you do, you will not be able to learn any other concepts.

Additionally, you might want to look at the Advanced Bash Scripting Guide and the Rute User's Tutorial and Exposition.

I would also urge you to try another distro for your learning experience. Kali Linux is specifically designed for Linux and networking experts and is really unsuitable for learning the basics - even dangerous to yourself and others in unknowledgable hands.
i won't anymore thanks
 
  


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
adding commands to a limited shell program khoh Programming 3 04-04-2011 09:50 AM
How to process billions of small files using Bash shell commands with limited memory? Osirix Linux - Newbie 1 05-26-2010 10:07 PM
Limited 'sudo' commands Casket Linux - Security 1 10-23-2007 02:05 AM
Limited permission on FTP user stefane321 Linux - Security 3 03-04-2005 07:21 PM
Limited Commands on RH9 with full install PenguinPwrdBox Red Hat 4 10-10-2003 08:03 PM

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

All times are GMT -5. The time now is 10:47 PM.

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