first line of a BASH script

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
Wally
Posts: 145
Joined: Sat 29 May 2010, 14:56
Location: Heaven, Dell X1:NO HDD, NO CD, NO FAN Pup 4.3.1 USB Boot............................ {RAP SUCKS!}

first line of a BASH script

#1 Post by Wally »

isn't it supposed to be

#!/bin/bash

so you can run the script without having to type './'

it won't work on mine.

muggins
Posts: 6724
Joined: Fri 20 Jan 2006, 10:44
Location: hobart

#2 Post by muggins »

Is the script executable?

Code: Select all

chmod +x script_name

User avatar
rhadon
Posts: 1292
Joined: Thu 27 Mar 2008, 11:05
Location: Germany

#3 Post by rhadon »

Code: Select all

#!/bin/bash
This in the first line means it's supposed to run in bash, instead of ash or something else.
Ich verwende "frugal", und das ist gut so. :wink:
Raspberry Pi without Puppy? No, thanks.

muggins
Posts: 6724
Joined: Fri 20 Jan 2006, 10:44
Location: hobart

#4 Post by muggins »

Plus, the file script_name, will only run as script_name if it's in the executable search PATH. Probably simplest to copy it to /usr/bin.

User avatar
Moose On The Loose
Posts: 965
Joined: Thu 24 Feb 2011, 14:54

#5 Post by Moose On The Loose »

muggins wrote:Plus, the file script_name, will only run as script_name if it's in the executable search PATH. Probably simplest to copy it to /usr/bin.
I put them in my-applications/bin

On puppy, my-applications/bin is in the search path and is nearly empty. As a result, it is easy to find the scripts I have made.

stu90

#6 Post by stu90 »

Moose On The Loose wrote:
muggins wrote:Plus, the file script_name, will only run as script_name if it's in the executable search PATH. Probably simplest to copy it to /usr/bin.
I put them in my-applications/bin

On puppy, my-applications/bin is in the search path and is nearly empty. As a result, it is easy to find the scripts I have made.
Yes i keep my scripts in the same place.

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#7 Post by amigo »

Calling a script using simply the program name requires the program/script to be executable. Calling them as an argument to the shell doesn't require them to be executable. Also, 'sourcing' them ( . path/to/script/or/program ) doesn't require them to be executable.

User avatar
Moose On The Loose
Posts: 965
Joined: Thu 24 Feb 2011, 14:54

#8 Post by Moose On The Loose »

amigo wrote:Calling a script using simply the program name requires the program/script to be executable. Calling them as an argument to the shell doesn't require them to be executable. Also, 'sourcing' them ( . path/to/script/or/program ) doesn't require them to be executable.
I didn't know that it didn't need to have the "x" set.


The

Code: Select all

. /root/my-applications/moose/defaults

if test -e  /root/my-applications/moose/settings; then
  . /root/my-applications/moose/settings
  fi

. /root/my-applications/moose/make_gui
... etc ..]
Is a nice way to do scripts if you don't mind a small hit on speed but like to keep the source for some things in its own file. The bit with the defaults and the settings is very good for making an application remember the choices the user made last time and using them as the default the next time. You just compose the settings file before you exit and it is done.

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#9 Post by amigo »

The real advantage to 'sourcing' is that all environment variables are available to the sourced code, without having to export anything. And, anything set (variable values) by the sourced script are available to the main script. Executing external scripts as separate processes does neither. Also, when sourcing an external script, the sourced file doesn't need any shebang at all.

Bruce B

#10 Post by Bruce B »

I guess it should be mentioned that script variables and functions persist when a script file is sourced.

~

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#11 Post by amigo »

"And, anything set (variable values) by the sourced script are available to the main script."

Bruce B

#12 Post by Bruce B »

amigo wrote:"And, anything set (variable values) by the sourced script are available to the main script."
True and while on the topic that's why I source Midnight Commander to run it. All my aliases are available to me.

I wonder how many people use Midnight Commander. I use as my only file manager. Except for Rox, when I want to view thumbnails for icons, xpm and other image files

I even removed Rox as the desktop manager. Just use JWM and its wallpaper features. One wallpaper for each desktop.

~

Post Reply