Tiny Core Linux

Tiny Core Base => TCB Q&A Forum => Topic started by: Paulo on March 07, 2013, 11:27:08 AM

Title: [SOLVED]Running a script in Terminal
Post by: Paulo on March 07, 2013, 11:27:08 AM
Hi all

I'm new to the forum and Linux so my apologies if I have posted in the wrong section.
My problem as follows:

I have created a bash script and a perl script, saved them in /home/tc and set the appropriate permissions
however I can't seem to run them from a Terminal.
I have confirmed with pwd that I am in the same directory as the scripts and if I type ./MyScript.pl or ./Myscript.sh
I always get an error that it's not found.
I have also tried exec but to no avail.
What am I missing?

Thanks in advance
Paulo.

BTW: I'm using the latest CorePlus and booting off a USB stick formatted as FAT32.
Title: Re: Running a script in Terminal
Post by: bmarkus on March 07, 2013, 11:35:47 AM
Install bash.tcz and perl5.tcz from repo they are not installed by default.
Title: Re: Running a script in Terminal
Post by: Rich on March 07, 2013, 11:46:58 AM
Hi Paulo
For future reference
Quote
I always get an error that it's not found.
What's not found? Bash? Myscript.sh?
Next time, please don't interpret the error, post the actual error message.
Title: Re: Running a script in Terminal
Post by: Paulo on March 07, 2013, 11:57:48 AM
Hi bmarkus and thanks for the quick reply.

Perl was installed but I used the wrong shebang in the perl script, it was #!/bin/perl and
when I changed it to #!/usr/bin/perl all is well.

As for Bash, the machine I'm using for TC does not have an internet connection but my Windows PC does
but it's from a USB 3G connection so can I download the bash.tcz file, copy it to my USB flash drive that has TC on it?

If so, should I put it into cde/optional ? and once there how do I install it on TC ?

Thanks
Paulo.
Title: Re: Running a script in Terminal
Post by: Paulo on March 07, 2013, 11:59:28 AM
Rich

Sorry about that, the complete error message as follows:

Code: [Select]
./MyScript.sh: not found
Title: Re: Running a script in Terminal
Post by: gerald_clark on March 07, 2013, 12:27:34 PM
Bash also requires ncurses and ncurses-common.
Are you sure you need bash?  Will #!/bin/sh ( busybox's ash ) suit your needs?
Title: Re: Running a script in Terminal
Post by: Paulo on March 07, 2013, 12:36:28 PM
Hi  gerald_clark

I would prefer to have bash as all of my scripts are for bash and I understand there are some
differences between bash and ash.

I see what you mean by the dependencies for bash, I downloaded bash.tcz on my Win box, then copied the file
across to the usb stick, putting into /cde/optional.
TC picked it up, installed it and is now complaining about libncurses.so.5 and I'm sure there will be more :-)
Tried to do a ldd on bash but there too it complains that it can't find the shared lib.
I don't mind hunting down the required libs on the net and my other nix boxes as long as I know which ones to get.
Anyone have a list of all the .so libs required by bash?

Thanks
Paulo.
Title: Re: Re: Running a script in Terminal
Post by: bmarkus on March 07, 2013, 12:59:04 PM
Hi bmarkus and thanks for the quick reply.

Perl was installed but I used the wrong shebang in the perl script, it was #!/bin/perl and
when I changed it to #!/usr/bin/perl all is well.

As for Bash, the machine I'm using for TC does not have an internet connection but my Windows PC does
but it's from a USB 3G connection so can I download the bash.tcz file, copy it to my USB flash drive that has TC on it?

If so, should I put it into cde/optional ? and once there how do I install it on TC ?

Thanks
Paulo.

You need .md5.txt and .dep files for a .tcz where .dep may be missing. .tree lists all packages a .tcz depends on.
Title: Re: Running a script in Terminal
Post by: Rich on March 07, 2013, 01:07:30 PM
Hi Paulo
Quote
I don't mind hunting down the required libs on the net and my other nix boxes as long as I know which ones to get.
There is nothing to hunt down. Any required lib that an app from the repository needs is in the repository.
Title: Re: Running a script in Terminal
Post by: Paulo on March 07, 2013, 01:13:48 PM
OK, understood but keep in mind that I don't have an internet connection on my TC box, so I'm using
my Win box to download the required files and then put them on the same usb drive as TC.

The only repo I could find is [ Removed ]
There are all the .tcz .info .list .md5 and in some cases a .dep (there are no .tree files).
However there is no .dep for bash.tcz
I tried downloading and installing ncurses-utils.tcz in the hope that it may contain the required libs but when
I try to install it there is an error:

Code: [Select]
mount: mounting /dev/loop32 on /tmp/tcloop/ncurses-utils failed: Invalid argument

     [EDIT]: Removed malformed link. Rich
Title: Re: Running a script in Terminal
Post by: Rich on March 07, 2013, 01:22:50 PM
Hi Paulo
You also need  ncurses.tcz
By the way, this is a bad way to do this. You would be better off if you used core2usb to install CorePlus to your
USB drive. Then boot that on your Windows machine and get the wireless connection set up. Then you can use
the Apps utility to install applications properly. Once they are installed, you can move the USB drive back to your
other machine.
Title: Re: Running a script in Terminal
Post by: bmarkus on March 07, 2013, 01:26:36 PM
Run TC in a virtual machine on WINDOWS to get familiar with package management and core concept.
Title: Re: Running a script in Terminal
Post by: Paulo on March 07, 2013, 01:48:45 PM
Rich

The problem is not a wireless connection, it's a USB 3G modem, so even if I run TC on my Win box via a VM or by booting into it,
TC can't see the 3G modem so I'm pretty stuck doing it this way.

OK found ncurses.tcz, loaded it and all working now.

Thank you all for your help and patience.
I will mark this as solved.
Title: Re: Running a script in Terminal
Post by: bmarkus on March 07, 2013, 02:03:40 PM
Rich

The problem is not a wireless connection, it's a USB 3G modem, so even if I run TC on my Win box via a VM or by booting into it,
TC can't see the 3G modem so I'm pretty stuck doing it this way.

OK found ncurses.tcz, loaded it and all working now.

Thank you all for your help and patience.
I will mark this as solved.


If you have nework access in WINDOWS, TC will see Internet from VM.
Title: Re: [SOLVED]Running a script in Terminal
Post by: Paulo on March 07, 2013, 02:12:15 PM
Hi bmarkus

I agree with what you say, but for some reason my 3G modem and Virtual Box are not good friends.
Anyhow I actually learnt a lot about TC doing it the "long" way.

Next I'm going to install Apache and I see that it has deps of apr-util.tcz, openssl-0.9.8.tcz and pcre.tcz
so I will download those too and install them first.
Title: Re: [SOLVED]Running a script in Terminal
Post by: bmarkus on March 07, 2013, 02:16:02 PM
Virtual Box has nothing to do with the 3G modem.
Title: Re: [SOLVED]Running a script in Terminal
Post by: Paulo on March 07, 2013, 02:20:08 PM
Could well be but TC definitely did not see an internet connection.
Not really a problem as I have ordered a router with 3G on it and 4 ethernet ports
so I will be able to give the TC box a straight ethernet connection when I get my router
in a couple of days.
Title: Re: Running a script in Terminal
Post by: tinypoodle on March 07, 2013, 06:52:02 PM
Perl was installed but I used the wrong shebang in the perl script, it was #!/bin/perl and
when I changed it to #!/usr/bin/perl all is well.
Declaring a perl script as
Code: [Select]
#!/usr/bin/env perlcould prevent such issues ;)
Title: Re: Running a script in Terminal
Post by: tinypoodle on March 07, 2013, 07:04:05 PM
I would prefer to have bash as all of my scripts are for bash and I understand there are some
differences between bash and ash.

This has nothing to do with preferences at all.
When bash encounters a script declared as
Code: [Select]
#!/bin/shit will automatically run in posix mode.

If a script which is posix compatible is declared as
Code: [Select]
#!/bin/bashthen that's a bug, while using bashisms where not required for functionality is simply bad coding ;)

Title: Re: Running a script in Terminal
Post by: tinypoodle on March 07, 2013, 07:18:09 PM
OK, understood but keep in mind that I don't have an internet connection on my TC box, so I'm using
my Win box to download the required files and then put them on the same usb drive as TC.

The only repo I could find is ftp://distro.ibiblio.org/pub/linux/distributions/tinycorelinux/tcz.html (http://ftp://distro.ibiblio.org/pub/linux/distributions/
tinycorelinux/tcz.html)
There are all the .tcz .info .list .md5 and in some cases a .dep (there are no .tree files).
However there is no .dep for bash.tcz

There is a script for downloading extensions without appbrowser access here:

http://forum.tinycorelinux.net/index.php/topic,7243.0.html

not sure to which extent it is still functional as of current.
Title: Re: [SOLVED]Running a script in Terminal
Post by: Paulo on March 08, 2013, 12:26:46 PM
Hi tinypoodle

Perhaps I'm misunderstanding you, but I thought that Bash and Ash were two different shells and interpreters
and Linux calls the selected interpreter depending on the shebang.

I can't see how putting bash in the shebang is considered bad programming considering how often it's used in the Linux environment.
Title: Re: [SOLVED]Running a script in Terminal
Post by: gerald_clark on March 08, 2013, 12:43:42 PM
Different  distros have different default shells.  The default shell is usually linked to /bin/sh.
Please re-read reply #18.
Title: Re: [SOLVED]Running a script in Terminal
Post by: Paulo on March 08, 2013, 12:57:02 PM
I understand that different distros use different default shells, just that I need to use Bash
because that is what is needed for BaCon (www.basic-converter.org).

I have since loaded Bash and all is well.


Title: Re: [SOLVED]Running a script in Terminal
Post by: bmarkus on March 08, 2013, 03:04:01 PM
I understand that different distros use different default shells, just that I need to use Bash
because that is what is needed for BaCon (www.basic-converter.org).

I have since loaded Bash and all is well.

OMG

It doesn't need bash. It is written in bash. A BASIC to C converter.

OMG
Title: Re: [SOLVED]Running a script in Terminal
Post by: Paulo on March 08, 2013, 03:33:14 PM
It needs BASH3.2 or later (+ gcc)
The convertor script will obviously not work without Bash as is the case with TC.

From the Bacon website:
Quote
BaCon Bash version (requires BASH 3.2 or higher)

There are other versions available that are in compiled form but the reason why I use the
Bash version is two fold:

1) I know Bash

2) The source is easy to change when needed.

As an example, I needed to use the BaCon command "USEC" (to embed C code into my Basic pgm) and one of the header files
I needed to use was io.h and BaCon was not creating the resulting C source code (and hence the final executable could not be compiled)
that included io.h, no problem I modified the BaCon Bash source and problem solved.

By the way, BaCon is more then a Basic to C convertor as it will create the elf executable as well by calling gcc and passing it the created C file.
It can also compile shared libs from Basic programs.
Title: Re: [SOLVED]Running a script in Terminal
Post by: tinypoodle on March 08, 2013, 11:09:55 PM
Hi tinypoodle

Perhaps I'm misunderstanding you, but I thought that Bash and Ash were two different shells and interpreters
and Linux calls the selected interpreter depending on the shebang.
Yes but...
- "#!/bin/sh" MUST be posix compliant on ANY UNIX-like system, which insures portability.
- If "#!/bin/sh" is a link to bash, then bash will automatically run in posix mode when encountering a script declared as "#!/bin/sh".
- ash - amongst other - is natively posix compliant, as opposed to bash.
- scripts declared as "#!/bin/bash" will ONLY run on systems where bash is installed AND linked to "#!/bin/bash"

Quote
I can't see how putting bash in the shebang is considered bad programming considering how often it's used in the Linux environment.

That is a total misrepresentation of what I said.

Let me try to put it differently:
1. posix compatible script declared as "#!/bin/bash" = bug
2. using bashisms where not required for functionality - and therefore creating a NEED for a "#!/bin/bash" declaration = bad coding
Title: Re: [SOLVED]Running a script in Terminal
Post by: Paulo on March 09, 2013, 02:27:56 AM
I understand that one can make a link to run Bash if #!/bin/sh is called however Bacon still needs Bash
or are you saying that if I change the shebang of Bacon.bash script (www.basic-converter.org/stable/bacon.bash)
it will run with no problems?

My intention is not to be argumentative however I can't see ash and bash being 100% compatible else the author
of BaCon would have mentioned something to that effect.

I know that Bash has attracted a lot of criticism but I have never had a problem on any distro by using #!/bin/bash
once Bash is installed.
Since I use BaCon a lot, I'm happy to overlook the fact that #!/bin/bash may not be 100% correct but it gets the job done.
I use Mint, Puppy, SysrescCD (Gentoo) and now TC and can write and compile apps in Basic on all of them now and by keeping
everything the same it makes my life a lot easier.
Title: Re: [SOLVED]Running a script in Terminal
Post by: tinypoodle on March 09, 2013, 02:38:24 AM
If you want to run scripts which explicitly depend on bash, then you have to install bash - and possibly link bash to /bin/bash on systems where that is not automatically done (it is with core).
Title: Re: [SOLVED]Running a script in Terminal
Post by: Paulo on March 09, 2013, 02:46:39 AM
I did install Bash on TC (see reply #12) , checked that #!/bin/bash does point to Bash and problem solved.
Title: Re: [SOLVED]Running a script in Terminal
Post by: tinypoodle on March 09, 2013, 03:35:41 AM
I know that Bash has attracted a lot of criticism but I have never had a problem on any distro by using #!/bin/bash
once Bash is installed.
I have witnessed users of a FreeBSD system being perplex how they could execute bash manually but their scripts declared as "#!/bin/bash" would not run.
Reason being that the administrator wouldn't link /usr/local/bin/bash to /bin/bash.
Title: Re: [SOLVED]Running a script in Terminal
Post by: Paulo on March 09, 2013, 03:50:46 AM
Those naughty admins need a good "bashing"  :)
Title: Re: [SOLVED]Running a script in Terminal
Post by: bmarkus on March 11, 2013, 09:18:56 AM
bacon is added to the repo.
Title: Re: [SOLVED]Running a script in Terminal
Post by: Rich on March 11, 2013, 11:24:59 AM
Hi bmarkus
The comments field in the info file reads  Compiled for RPI. I don't see  bash.tcz  in the  .deps  file, did you
remove that as a requirement?
Title: Re: [SOLVED]Running a script in Terminal
Post by: bmarkus on March 11, 2013, 11:42:48 AM
@Rich

I built it for both RPi and x86 and forgot to edit x86 info file, thanks for noting.

It's an elf binary, you do not need bash at all. Story is interesting. bacon is provided as a bash (or korn) shell script and in BASIC. First time you build the compiler (bacon.bac) with bacon.bash to get the the executable elf binary. When you have it no need for the bash compiler anymore. Also compiled it with the executable version. While it is faster than the bash version, got the same result with default option. Compiling with -O2 however get smaller and faster compiler.

I'm not a fun of BASIC and specially hate VBS I have to use frequently on WINDOWS, this bacon offers features like internationalization of messages, creation and use shared object files, networking, etc. Also have bencmarking C, LUA, LUAJIT, Perl, Python and bacon where bacon performing fine.

So, on LINUX it can be a feasible alternative tool if portability to WINDOWS is not needed.
Title: Re: [SOLVED]Running a script in Terminal
Post by: Rich on March 11, 2013, 12:16:36 PM
Hi bmarkus
Thanks for the explanation, that would have been worthwhile for them to mention on their website. While also not
a big fan of BASIC, about 10 years ago I played around a bit with VB3 and VB4. VB3 was nice, built reasonably
small executables, and if something was to slow, like plotting a lot of data points, you could make a call to one
of the system DLLs to do it for you.
Title: Re: [SOLVED]Running a script in Terminal
Post by: bmarkus on March 11, 2013, 12:34:29 PM
It is just the usual bootstrapping to install a compiler, nothing special, so I can understand why it is not mentioned.
Title: Re: [SOLVED]Running a script in Terminal
Post by: Paulo on March 11, 2013, 01:35:31 PM
Hi bmarkus

Thanks for adding BaCon to the repo.

I have always believed that one of the stumbling blocks for beginner programmers on Linux is the availability of a simple to understand
language which hides the inner workings of Linux and thus allows one to gain confidence, plus many programmers coming from the
Windows world will invariably have used VB.
BaCon fills this gap very nicely.

Although I also use C and ASM, BaCon is particularly nice for making small GUI apps and the network features of it saves lots of time compared to C or C++.

What I like most about BaCon is the ability to use shared libs and also to create them, where as VB can only use the Windows
version of shared libs (DLLs) but can't compile them.

By the way, did you include HUG.bac when you compiled BaCon?

Title: Re: [SOLVED]Running a script in Terminal
Post by: bmarkus on March 11, 2013, 02:15:56 PM
By the way, did you include HUG.bac when you compiled BaCon?

No
Title: Re: [SOLVED]Running a script in Terminal
Post by: Lee on March 11, 2013, 02:22:29 PM
My apologies, but I found this great youtube video about the many uses of bacon...

http://www.youtube.com/watch?v=wSReSGe200A

:)
Title: Re: [SOLVED]Running a script in Terminal
Post by: Paulo on March 11, 2013, 02:42:49 PM
@Lee
Very funny video, thanks for sharing.  ;D

@bmarkus

You gonna have to rub some bacon on it as hug.bac is required for GUI apps.
Will the compiled version still work if one adds:
INCLUDE hug.bac
in the Basic source?
Sorry for asking as I have never used the compiled version of BaCon, only the Bash version.
Title: Re: [SOLVED]Running a script in Terminal
Post by: Rich on March 11, 2013, 02:46:02 PM
Hi Paulo
Bmarkus doesn't   "have to"  do anything. Try asking nicely.
Title: Re: [SOLVED]Running a script in Terminal
Post by: Paulo on March 11, 2013, 02:48:36 PM
@Rich

It was meant in a humorous manner in keeping with the youtube video.
Title: Re: [SOLVED]Running a script in Terminal
Post by: Rich on March 11, 2013, 03:03:16 PM
Hi Paulo
I didn't watch the video since I don't have flash installed on this machine. Regardless, it was the wording I
objected to which reads more like a demand than a request, as opposed for example to writing it something like:
Code: [Select]
Maybe you could rub some bacon on it? As hug.bac is required for GUI apps.
Title: Re: [SOLVED]Running a script in Terminal
Post by: tinypoodle on March 11, 2013, 03:22:47 PM
I didn't watch the video since I don't have flash installed on this machine.
http://forum.tinycorelinux.net/index.php/topic,3721.msg85608.html#msg85608
;)
Title: Re: [SOLVED]Running a script in Terminal
Post by: Paulo on March 11, 2013, 03:27:02 PM
Hi Rich

Had you watched the video, I suspect that your view would have been very different
and since my request/demand (depending on how one interprets it) was directed at bmarkus,
I would be interested in his view about it.
Title: Re: [SOLVED]Running a script in Terminal
Post by: Rich on March 11, 2013, 03:51:45 PM
Hi Paulo
Well I didn't watch it, and you don't know that bmarkus did either. But your right, it is up to bmarkus, and that gets
us back to the initial point:

  It's the difference between taking it for granted someone must do something for you as opposed to asking if they
  would do something for you.

And on that note I'll drop it.

@tinypoodle: This machine has no sound capability, so videos are kind of pointless.
Title: Re: [SOLVED]Running a script in Terminal
Post by: Paulo on March 11, 2013, 04:05:19 PM
Rich

I never demanded that bmarkus do anything, you assumed that I did and it's certainly not my fault that for whatever
reasons you don't/can't watch youtube content and hence did not get the spirit of my post.

I shall now drop it too and let's leave it at we agree to disagree.
Title: Re: [SOLVED]Running a script in Terminal
Post by: bmarkus on March 12, 2013, 03:06:02 AM
@Lee
Very funny video, thanks for sharing.  ;D

@bmarkus

You gonna have to rub some bacon on it as hug.bac is required for GUI apps.
Will the compiled version still work if one adds:
INCLUDE hug.bac
in the Basic source?
Sorry for asking as I have never used the compiled version of BaCon, only the Bash version.

No need to include wrappers in compiler (converter) source, they are used in applications only Same for HUG which is the GTK wrapper. Add to your program if creating a GTK+ application.
Title: Re: [SOLVED]Running a script in Terminal
Post by: Paulo on March 12, 2013, 04:31:57 AM
Thank you bmarkus.