How to Create a Simple Executable Script <SOLVED>

All Gurus once were Newbies
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Please stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions prefer the other forums within the support section.
Before you post please read how to get help
Post Reply
Michaias
Level 1
Level 1
Posts: 6
Joined: Sat Aug 12, 2017 7:44 am

How to Create a Simple Executable Script <SOLVED>

Post by Michaias »

Warning: super noob question.

I'm trying to write and execute a really simple script. Let's start with Hello, world! (I want to do something slightly more complicated, but let's get this basic thing down first).

I'm running Linux Mint 18.2 Cinnamon 64-bit (Cinnamon version 3.4.3).

So, I was following the guidelines on this webpage, and even this basic guide has stumped me: http://linuxcommand.org/lc3_wss0010.php

I installed gedit. I opened gedit. I typed the following into gedit:

#!/bin/bash
# My first script

echo "Hello World!"

________
Then, I saved the text file in a newly-created folder: Home/bin
File name: hello_world

Now, I fire up the terminal and type the following:
chmod 755 hello_world

I receive the following error:
chmod: cannot access 'hello_world': No such file or directory

But I can see that file in the GUI. Where am I going wrong?
I feel like a dummy with a set of house keys I'm trying to force into a car ignition.
Last edited by Michaias on Sat Aug 12, 2017 9:23 am, edited 1 time in total.

User avatar
austin.texas
Level 20
Level 20
Posts: 12047
Joined: Tue Nov 17, 2009 3:57 pm
Location: at /home

Re: How to Create a Simple Executable Script

Post by austin.texas »

You want to create the bin directory in the right location. It would be /home/yourusername/bin
Then it automatically becomes part of your $PATH, and the script will be executed without changing directories to /home/yourusername/bin
HOWEVER... in order to chmod the script, you first have to cd to the bin directory, or enter the complete path - e.g. /home/yourusername/bin/hello_world
Mint 18.2 Cinnamon, Quad core AMD A8-3870 with Radeon HD Graphics 6550D, 8GB DDR3, Ralink RT2561/RT61 802.11g PCI
Linux Linx 2018

itsme4401
Level 3
Level 3
Posts: 168
Joined: Sat Nov 27, 2010 4:12 pm
Location: Netherlands

Re: How to Create a Simple Executable Script

Post by itsme4401 »

Then, I saved the text file in a newly-created folder: Home/bin
Well, that's something you know, but.. your computer doensn't!
To make clear to your computer that you have made a new directory that should be searched for executables, add the path to it to the existing path by:

Code: Select all

export PATH=$PATH:/Home/bin 
assuming "Home/bin" is the exact name of the path to the directory (Exact refers to Captal/undercase too!!)
Austin.texas is better in English, so quicker as I am! Sorry.

Michaias
Level 1
Level 1
Posts: 6
Joined: Sat Aug 12, 2017 7:44 am

Re: How to Create a Simple Executable Script

Post by Michaias »

Thank you, both! It worked!

The cd command was the step I was missing. I knew it would be something painfully simple.

I'll try my more complicated script now and maybe post another dumb question about that one.

Post Reply

Return to “Newbie Questions”