should I use the text editor? the extension should be .sh or .bat?
-
1Your question is more likely to receive useful answers if it contains some specifics. Such as what type of data is to be processed, including realistic examples of input and output.– J. StarnesNov 3, 2017 at 0:54
-
@SergiyKolodyazhnyy The duplicate nominee is closed as too broad. As such the close vote on this one should be "too broad" as well. That said it seems like a reasonable question to me as I was once in the dark myself :)– WinEunuuchs2UnixNov 3, 2017 at 1:13
-
@WinEunuuchs2Unix It is closed but does have an accepted answer, which will give OP what they want, or at least a starting point.– Sergiy KolodyazhnyyNov 3, 2017 at 1:30
-
@EliahKagan If a mod agrees perhaps he can reopen that one and then merge the answers from here to there?– WinEunuuchs2UnixNov 3, 2017 at 10:56
-
@WinEunuuchs2Unix That question, which this received close votes to be duped to, was actually reopened a few hours ago, then closed again as duplicate of that highly voted question. Both of them are listed as "originals" in the duplicate banner here (i.e., this question is duped to both of them). So if answers are to be merged, they'd probably be put there. Do you think that would be useful?– Eliah KaganNov 3, 2017 at 11:04
3 Answers
To create one use the .sh
extension but it doesn't really matter but it helps future users to quickly determine which file type it is. The bat
name is mostly used on Windows but in Linux file name extensions do not really matter. Meaning I can call my file say run.de
and it would still run in bash
file but I believe it's a good practice to name them with the .sh
file extension.
For the editor, part uses any that is best for you between nano vim gedit emacs
, but I believe gedit
would be nice to start with.
How to:
using gedit
text editor:
Create the file:
gedit runme.sh
Add code into file:
#!/bin/bash echo "Hello World!"
Make file executable:
chmod +x runme.sh
Run the file from terminal:
./runme.sh
In linux they are bash scripts. You can use most any editor and you can call it what you wish, Linux does not use extensions such as .sh or .bat or .exe to .doc to identify files, it uses magic.
Probably gedit for a graphical editor and nano from the command line.
Avoid word processors such as libre office as they add headers you don't want.
http://www.linfo.org/magic_number.html
To write a bash script , start the file with a "SheBang" or #!/bin/bash
#!/bin/bash
# comments start with a '#"
command 1
command 2
Tons of tutorials on the web - https://linuxconfig.org/bash-scripting-tutorial
Batch file equivalent in linux is shell script (.sh). You can use gedit, vim or any other text editor available to create one.
A good start for begginers is http://www.tldp.org/LDP/Bash-Beginners-Guide/html/index.html.
Hope this helps :)
-
-
@WinEunuuchs2Unix Yep link should be tldp.org/LDP/Bash-Beginners-Guide/html/index.html , I'll edit that in. Nov 3, 2017 at 1:23