Forum Moderators: bakedjake

Message Too Old, No Replies

Linux .bat files

         

engine

12:32 pm on Dec 18, 2020 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I use my own batch files to help carry out tasks in Windows.

What's the equivalent in Linux?

Any help to start creating in Linux?

brotherhood of LAN

12:40 pm on Dec 18, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



.sh files, bash

The extension doesn't really matter but the convention is to use .sh

It will take the same commands/logic you perform on the command line

e.g. show the filesystem in the current working directory, example.sh

ls -al .

bash example.sh

lammert

12:45 pm on Dec 18, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The commonly used command interpreter is bash, but you can use different interpreters depending on your needs. Even Perl, Python or PHP is possible. The first line in a shell script defines the interpreter to use. For example, this line tells the system to use bash for the processing:
#!/bin/bash

Change that line to the interpreter you like and you can write shell scripts in your preferred language.

graeme_p

2:20 pm on Dec 18, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The direct equivalent of .bat is usually bash scripts with a .sh extension (does not matter, but editors will highlight it correctly by default if you use it).

if you use #!/bin/bash or #!/bin/sh you also need to mark the file executable (chmod a+x example.sh) and then you can run it with ./example.sh

Otherwise (slightly ess securely) you can put scripts you run regularly in a directory you add to your path environment variable.

Bash is usually easiest for automation of things you do from the command line because it is probably what you are using as the command line shell.

As @lammert says you can use other languages to write scripts in. Just about any interpreted language so there is a vast array to choose from. Perl and Python are popular choices, TCL is unfashionable but well suited to that role.

Start with Bash though, its what everyone uses.

engine

2:24 pm on Dec 18, 2020 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Bash, thank you, I appreciate your patience with this novice.

phranque

11:50 pm on Dec 18, 2020 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



The first line in a shell script defines the interpreter to use.


there is specific lingo for this:
Shebang [en.wikipedia.org]

(i prefer "hashbang" but that terminology was, at least temporarily, assumed by google's ill-advised "AJAX crawling scheme" [youtube.com])

another fundamental contribution by dennis ritchie...