LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-23-2022, 02:00 PM   #16
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,678

Rep: Reputation: Disabled

Quote:
Originally Posted by rnturn View Post
I wonder if this wasn't intended to be used along with another script called "sshin" though I can't know just what passing "(END)" to it would do.
I guess that line was just a comment for readers marking the end of the script as part of a larger post (not every site has [code][/code] tags like here at LQ). And was mistaken by OP for a part of the script.
 
Old 02-23-2022, 02:10 PM   #17
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,784

Rep: Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937
Quote:
I do have one more question. From where does bash understands <sshin> since the line is deleted now?
Totally unrelated. sshin is your script name which resides in your /home/username/programs directory. Since /home/username/programs is in your environment path and executable (I assume) you can run your script by just typing at the prompt

sshin XX

As an exercise you can add some error checking to your script to verify that you included a number and that it is valid.
 
Old 02-23-2022, 02:25 PM   #18
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,678

Rep: Reputation: Disabled
Quote:
Originally Posted by Debian6to11 View Post
From where does bash understands <sshin> since the line is deleted now?
You obviously made the script executable and put it into a directory on your PATH.

When you issue the command sshin 12, Bash sees the first word of the command is an executable in one of the directories on the PATH, calls the kernel via execve(2) system call, and passes it the parsed command line.

The kernel, in turn, sees the shebang #!/bin/bash in the first line, understands it is a script, and calls the script interpreter (/bin/bash) with the script name as the first parameter preserving the parameters passed to it by the first instance of bash as the rest of the command line. As if you called it
Code:
/bin/bash sshin 12

Last edited by shruggy; 02-23-2022 at 02:31 PM.
 
Old 02-23-2022, 04:54 PM   #19
Debian6to11
Member
 
Registered: Jan 2022
Location: Limassol, Cyprus
Distribution: Debian
Posts: 382

Original Poster
Blog Entries: 1

Rep: Reputation: 71
Thanks for your answers, you have been helpful and explained well. I'm a newcomer at scripting, this is all new to me.
 
Old 02-23-2022, 08:07 PM   #20
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,691
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
FYI: "I usually never write 'Bash scripts.'" Simply because I know that I can write the first line: (say ...) #!/usr/bin/pick_something and thereafter write my entire script in ("pick_something") a real programming language. And my customers will never know or care.

Two simple characters at the very-beginning of an "executable" file ... "#!" ... ("shebang!") ... never meant so much.

Last edited by sundialsvcs; 02-23-2022 at 08:11 PM.
 
Old 02-24-2022, 06:19 AM   #21
Debian6to11
Member
 
Registered: Jan 2022
Location: Limassol, Cyprus
Distribution: Debian
Posts: 382

Original Poster
Blog Entries: 1

Rep: Reputation: 71
To me they look like, read the next lines in sequence.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
httpd: Syntax error on line 210 of /etc/httpd/conf/httpd.conf: Syntax error on line 6 iswarya Linux - Newbie 1 01-25-2012 01:28 PM
[python] syntax Error : invalid syntax Python_user Programming 2 09-06-2009 12:52 PM
[SOLVED] "Error: syntax before '@' token and Error: syntax at 'OTHER' token" bullrider Programming 2 07-27-2009 08:00 AM
Starting httpd: httpd: Syntax error on line 209 of /etc/httpd/conf/httpd.conf: Syntax sethukpathi Linux - Networking 6 04-12-2008 11:26 AM
C++ syntax error before :: token HELP, i cant find the syntax error :( qwijibow Programming 2 12-14-2004 06:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration