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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
|
07-14-2017, 03:13 PM
|
#1
|
LQ Newbie
Registered: Jul 2017
Posts: 19
Rep:
|
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
Last edited by Abdulmalek97; 07-14-2017 at 04:12 PM.
|
|
|
07-14-2017, 03:35 PM
|
#2
|
Moderator
Registered: Aug 2002
Posts: 26,201
|
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/
|
|
|
07-14-2017, 03:40 PM
|
#3
|
LQ Newbie
Registered: Jul 2017
Posts: 19
Original Poster
Rep:
|
Quote:
Originally Posted by michaelk
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?
|
|
|
07-14-2017, 03:58 PM
|
#4
|
Moderator
Registered: Aug 2002
Posts: 26,201
|
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!"
|
|
|
07-14-2017, 04:17 PM
|
#5
|
LQ Newbie
Registered: Jul 2017
Posts: 19
Original Poster
Rep:
|
Quote:
Originally Posted by michaelk
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?
|
|
|
07-14-2017, 04:21 PM
|
#6
|
Moderator
Registered: Aug 2002
Posts: 26,201
|
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.
|
|
|
07-14-2017, 04:23 PM
|
#7
|
LQ Newbie
Registered: Jul 2017
Posts: 19
Original Poster
Rep:
|
Quote:
Originally Posted by michaelk
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.
|
|
|
07-14-2017, 04:30 PM
|
#8
|
Moderator
Registered: Aug 2002
Posts: 26,201
|
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.
|
|
|
07-14-2017, 04:31 PM
|
#9
|
LQ Newbie
Registered: Jul 2017
Posts: 19
Original Poster
Rep:
|
Quote:
Originally Posted by michaelk
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.
|
|
|
07-14-2017, 04:38 PM
|
#10
|
LQ Newbie
Registered: Jul 2017
Posts: 19
Original Poster
Rep:
|
Quote:
Originally Posted by michaelk
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.
|
|
|
07-14-2017, 04:44 PM
|
#11
|
Moderator
Registered: Aug 2002
Posts: 26,201
|
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.
|
07-14-2017, 04:49 PM
|
#12
|
Moderator
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,297
|
Quote:
Originally Posted by Abdulmalek97
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.
|
07-14-2017, 05:01 PM
|
#13
|
Moderator
Registered: Aug 2002
Posts: 26,201
|
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.
|
07-14-2017, 05:02 PM
|
#14
|
LQ Newbie
Registered: Jul 2017
Posts: 19
Original Poster
Rep:
|
Quote:
Originally Posted by michaelk
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
|
|
|
07-14-2017, 05:06 PM
|
#15
|
LQ Newbie
Registered: Jul 2017
Posts: 19
Original Poster
Rep:
|
Quote:
Originally Posted by astrogeek
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
|
|
|
All times are GMT -5. The time now is 06:26 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|