Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED]Małe pytanie na temat skryptów
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Polskie forum (Polish) Polish OTW
View previous topic :: View next topic  
Author Message
matt1366613
n00b
n00b


Joined: 05 Feb 2009
Posts: 48

PostPosted: Mon Apr 06, 2009 9:47 am    Post subject: [SOLVED]Małe pytanie na temat skryptów Reply with quote

Witam.
Czy ktoś mógłby mi wytłumaczyć jakie są różnice w skryptach zaczynających się od
#!/bin/bash
oraz
#!/sbin/sh
i tak dalej.
Czy to ma tylko charakter informacyjny że dany skrypt jest na przykład skryptem basha a inny nie czy jest w tym coś więcej?
Ewentualnie prosiłbym o odesłanie do jakiejś strony gdzie jest to opisane bo nie mogę znaleźć.


Last edited by matt1366613 on Mon Apr 06, 2009 11:17 am; edited 1 time in total
Back to top
View user's profile Send private message
no4b
Bodhisattva
Bodhisattva


Joined: 18 Jan 2004
Posts: 774
Location: Tarnów, Poland

PostPosted: Mon Apr 06, 2009 10:50 am    Post subject: Reply with quote

W większości dystrybucji sh jest linkiem do basha, więc tam nie ma to znaczenia, ale np we FreeBSD już nie jest. Dlatego ma to znacznie dla przenośności. Jeśli nie używasz składni, którą akceptuje tylko bash lepiej używać #!/bin/sh.
_________________
GTK2/GNOME - The weakest link!
Back to top
View user's profile Send private message
matt1366613
n00b
n00b


Joined: 05 Feb 2009
Posts: 48

PostPosted: Mon Apr 06, 2009 11:17 am    Post subject: Reply with quote

Wielkie dzięki.
Back to top
View user's profile Send private message
canis_lupus
l33t
l33t


Joined: 22 Dec 2005
Posts: 773
Location: Kraków

PostPosted: Tue Apr 07, 2009 10:14 am    Post subject: Reply with quote

a czemu to jest zakomentowane?
_________________
"I love you cię" Różyczko...
Back to top
View user's profile Send private message
Ahenobarbi
Retired Dev
Retired Dev


Joined: 02 Apr 2009
Posts: 345
Location: Warsaw, PL

PostPosted: Tue Apr 07, 2009 11:17 am    Post subject: Reply with quote

canis_lupus wrote:
a czemu to jest zakomentowane?

Żeby ludzie, którym się nie chce pisać tej linijki mogli ją pominąć i nie mieć z tego powodu problemów?
Back to top
View user's profile Send private message
SlashBeast
Retired Dev
Retired Dev


Joined: 23 May 2006
Posts: 2922

PostPosted: Tue Apr 07, 2009 11:38 am    Post subject: Reply with quote

Przeca jak plik ma +x i go wywolamy ./plik to musi byc wiadomo, w czym to odpalic, dlatego jest tam bash, sh, python, perl czy inne wpisane.
Dlugosc #! nie moze miec wiecej niz 25znakow, z tego co pamietam.
Back to top
View user's profile Send private message
znal
Apprentice
Apprentice


Joined: 12 Jul 2007
Posts: 190

PostPosted: Tue Apr 07, 2009 3:43 pm    Post subject: Reply with quote

To co jest po #! w 1 linii pliku mówi jaki ma być interpreter dla danego pliku. W momencie wywołania dodawana jest do tego nazwa skryptu. Interpreterem może być cokolwiek, nie tylko bash, perl itp. np. taki skrypt sam wypisze swoją zawartość:
Code:
#!/bin/cat
tekst

ZTCW nie ma specjalnych ograniczeń na długość tej linii, wszystko co wystąpi po nazwie polecenia jest jego parametrem (jako czysty tekst). Jeśli powłoką jest bash, a skrypt nie ma określonego interpretera, to domyślnie jest traktowany jako skrypt basha. Więcej info w man bash.
Back to top
View user's profile Send private message
SlashBeast
Retired Dev
Retired Dev


Joined: 23 May 2006
Posts: 2922

PostPosted: Tue Apr 07, 2009 3:57 pm    Post subject: Reply with quote

Na 100% jest ograniczenie co do ilosci znaków w tej lini, tylko nie moge sobie przypomniec jakie.
Back to top
View user's profile Send private message
XianN
Tux's lil' helper
Tux's lil' helper


Joined: 21 Jan 2006
Posts: 82
Location: .wroc.pl

PostPosted: Sat Apr 11, 2009 2:39 am    Post subject: Reply with quote

No to taki szybki tescik zrobimy i pokazemy, ze SlashBeast ma racje:)

Code:
xiann@heifer ~/bin $ ./dlugi.sh
#!/bin/../bin/../bin/../bin/../bin/../bin/../bin/../bin/../bin/../bin/../bin/../bin/../bin/../bin/../bin/../bin/../bin/cat

xiann@heifer ~/bin $ sed 's:cat$:../bin/cat:' dlugi.sh | tee dlugi.sh
#!/bin/../bin/../bin/../bin/../bin/../bin/../bin/../bin/../bin/../bin/../bin/../bin/../bin/../bin/../bin/../bin/../bin/../bin/cat

xiann@heifer ~/bin $ ./dlugi.sh
bash: ./dlugi.sh: /bin/../bin/../bin/../bin/../bin/../bin/../bin/../bin/../bin/../bin/../bin/../: zły interpreter: Nie ma takiego pliku ani katalogu
xiann@heifer ~/bin $
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Polskie forum (Polish) Polish OTW All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum