What language or script are .sh files written in? (Solved)

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
RSH
Posts: 2397
Joined: Mon 05 Sep 2011, 14:21
Location: Germany

What language or script are .sh files written in? (Solved)

#1 Post by RSH »

Hi,

i got some questions about the language that is used in the .sh files. I am a PASCAL Programmer and try to translate this code to PASCAL while i'm reading. Gives me a little help, to understand the code. What is the name of this script-language? MUST HAVE TO KNOW THIS. Where can i get a full-list of functions etc? MUST HAVE TO KNOW THIS AS WELL.

My Problem MUST HAVE TO KNOW THIS ABSOLUTELY and TOTALLY: i need some equivalent functions to some PASCAL string operating functions.

I have got yet from L18L the following:
PASCAL: (put strings together)

s1:='User';
s2:='RSH'
concat(s1,' ',s2)

returns the String "User RSH".

Equivalent:

s1='User'
s2='RSH'
echo "$s1 $s2"
returns the String "User RSH"
please check this: s=echo "$s1 $s2" (<--please take a look at this - syntax, missing chars? " ' ' etc.?)

PASCAL: (get the position of a char or string)

position:=pos(' RSH',s1) returns 6 (the position of ' ')

Equivalent:

pos=INSTR("Hallo RSH", " RSH") returns 6 (the position of ' ')
maintainly needed, the equvalent functions to the following list:

PASCAL:

n:=length(s1) n returns 4, length of s1

delete(s1,start,anz)
delete(s1,3,2) returns "Us" (delet 2 chars at position 3)

insert(s1,'n',2) after this s1 (User) is s1 (Unser = german equivalent to "our")
Hope, help is on the way...

RSH
Last edited by RSH on Tue 01 Nov 2011, 04:13, edited 2 times in total.

PANZERKOPF
Posts: 282
Joined: Wed 16 Dec 2009, 21:38
Location: Earth

Re: HELP needed

#2 Post by PANZERKOPF »

RSH wrote: maintainly needed, the equvalent functions to the following list:
PASCAL:
n:=length(s1) n returns 4, length of s1
delete(s1,start,anz)
delete(s1,3,2) returns "Us" (delet 2 chars at position 3)

insert(s1,'n',2) after this s1 (User) is s1 (Unser = german equivalent to "our")
RSH
Note Pascal is richer than ShellScript. Do not compare them.
Some tricks:
S1="Hello!"
echo ${S1:0:1} # prints H ${variable:position:length}
echo ${S1:0:3} # prints Hel
echo ${S1:2:3} # prints llo
echo ${#S1} # prints 5 (length)
echo ${S1/lo/p} # prints Help
SUUM CUIQUE.

User avatar
RSH
Posts: 2397
Joined: Mon 05 Sep 2011, 14:21
Location: Germany

#3 Post by RSH »

Hi PANZERKOPF,

thanks for your reply. PASCAL is richer than ShellScript, i know this for sure. And now i know the name is "ShellScript". Thanks. But string functions are standard functions on every pc and in every programming or programming-like language i've seen. So i've been suer, there must be some equivalent stuff to the PASCAL functions.

So. can i do things like

Code: Select all

echo ${S1:2-1:3+1}
and what must be done to put the result as a string into a textfile?

In PASCAL it is:

Code: Select all

writeln(file,s1);
thanks, RSH

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#4 Post by big_bass »

Hey RSH

it may be easier for you to jump into BaCon which looks "closer" to the Pascal syntax

bash uses built in and external compiled binaries to do one job well
the only problem is a lot of command options for each one




http://tldp.org/LDP/abs/html/string-manipulation.html

Code: Select all

stringZ=abcABC123ABCabc
echo ${#stringZ}                 # 15


the easy way

Code: Select all

s1='before'
s2='after'
line="HALLO RSH"
echo "$s1 $line $s2"


the more complex way but sed lets you replace words in files
one example I will give calls sed an external binary with awful syntax to read

1.)set a string value line="HALLO RSH"
2.) output to the display the string and "pipe" send this info to another command
which in this case is sed
3.) use a second new string before
4) the & is your original string which will be repeated
5)after is your third new string

Code: Select all

  
line="HALLO RSH"
echo $line | sed -n 's/'"$line"'/before & after /p'
  

we posted at the same time so I have just seen this

Code: Select all

echo ${S1:2-1:3+1} >somefile.txt
Joe
Last edited by big_bass on Sun 30 Oct 2011, 03:56, edited 3 times in total.

User avatar
RSH
Posts: 2397
Joined: Mon 05 Sep 2011, 14:21
Location: Germany

#5 Post by RSH »

Hi, big_bass.

Thanks a lot. This stuff is what i needed and it is really much. Seems like i've got enough work for the next week(s) yet.

I have heard and read a little about BaCon. I have searched for it as well but didn't found it. Do i have to compile BaCon-files to use them? This is what i like by using ShellScript: no need to compile.

Do you know a active Link to BaCon (a .pet, not the source)?

RSH

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#6 Post by big_bass »

PASCAL: (put strings together)

s1:='User';
s2:='RSH'
concat(s1,' ',s2)

returns the String "User RSH".

Equivalent:

s1='User'
s2='RSH'
echo "$s1 $s2"
returns the String "User RSH"
please check this: s=echo "$s1 $s2" (<--please take a look at this - syntax, missing chars? " ' ' etc.?)
you can do this a few ways

Code: Select all

s1='User'
s2='RSH'
echo "$s1 $s2"

s="$s1 $s2"
echo $s
or you use back ticks small to see around the `echo "$s1 $s2"`
that runs the command and the result is in s=


Code: Select all

s1='User'
s2='RSH'
s=`echo "$s1 $s2"`
echo $s
Do you know a active Link to BaCon (a .pet, not the source)?
I dont know what version of puppy you are on but
it doesnt matter if you have the devx installed (the compiler)
this script will do all the work for you to get going
http://www.murga-linux.com/puppy/viewto ... 36&start=3

check the commands
http://www.basic-converter.org/documentation.html

what you were trying to do above

Code: Select all

concat(s1,' ',s2) 
but using BaCon

Code: Select all

CONCAT$

CONCAT$(x$, y$, …)

Type: function

Returns the concatenation of x$, y$, ... The CONCAT function can accept an unlimited amount of arguments. Example:

PRINT CONCAT$("Help this is ", name$, " carrying a strange ", thing$)
Joe

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#7 Post by technosaurus »

to really understand it all takes practice and it helps to read the advanced bash scripting guide - for your particular question, the section on substring manipulation will have everything you need

http://tldp.org/LDP/abs/html/
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
RSH
Posts: 2397
Joined: Mon 05 Sep 2011, 14:21
Location: Germany

#8 Post by RSH »

Hello,

thanks to all for help and hints.

I was able to create the tool, i wanted to create. It works fine.

The created tool is a right-click file-split-tool. I want it to split large .iso files, to save it on the web. Now it works for all files, doesn't matter, where the files are. It saves a script inside the directory, where the splitted files have been saved,. The scipt rebuilds the splitted .iso, .sfs, .mpg (video), .avi (msvideo). Listed files are predefined. To make it usable for other files, just copy the "Split File"-link into another ROX-App folder.

The Code is fully commended in german and english. So, i think, it maybe interesting to take a look inside.

The pet is here:

http://murga-linux.com/puppy/viewtopic. ... 2&start=15

RSH

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#9 Post by Lobster »

I started with Pascal, still my second favourite language
My favourite language is the commercial CURL
http://www.curl.com/products/prod/language/
. . . which is totally unsuitable for Puppy as it requires a run time
library component . . .

RSH now that you have devx you are well on the way to creating useful programs. You have already demonstrated this.

I tend to create a basic program with gtkdialog and shellscript
usually calling a command line program.

This often does what I want.
An example might be an early pwget
http://murga-linux.com/puppy/viewtopic. ... 053#165053

This is fast and dirty but works.
The smarter guys like you, usually come and improve 8)

Anyway good luck :)
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

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

#10 Post by Moose On The Loose »

Lobster wrote:I started with Pascal, still my second favourite language
FreePascal works if you put the devx in. It needs the linker to work.

You can code in your 2nd fav language.

Post Reply