[완료]source 와 ./ 명령 차이

boardholic의 이미지

제가 java관련 프로젝트 빌드를 할려고 하는데요.

ex)
source ads120 <- 이럴때는 ads120에 적용된 path가 제대로 잡히는데요.
./ads120 <- 이렇게 하면 path가 잡히질 않네요.

컴파일 시에도
source build java <- 이렇게 하고나면, 현재 디렉토리가 다른곳으로 바껴져있어요 -_-
그러나 ./build java <- 이렇게 하면 현재 디렉토리 그대로입니다.

무슨 차이인가요?

eminency의 이미지

./ads120

이렇게 실행하면 일반적인 실행 파일을 실행하는 것과 동일한 방식으로 실행합니다.
즉, shell 프로세스가 fork()되고, fork된 다른 프로세스에서 실행 파일을 동작시키는 방식입니다. 실행이 끝나면 프로세스가 사라지고 현재 shell의 프로세스로 돌아오므로 현재 shell에 영향을 미치지 않습니다.

source ads120

하지만 이렇게 실행시키면 현재 shell에서 스크립트 파일을 직접 읽어서 바로 실행을 하게 됩니다. 즉, 현재 shell에 영향을 미치게 되지요.
그러므로 환경 변수나 현재 shell의 환경을 변경할 필요가 있다면 source ads120(또는 . ads120)으로 하는 것이 맞습니다.

* source 명령은 쉘 스크립트에 대해서만 동작합니다.

노루가 사냥꾼의 손에서 벗어나는 것 같이, 새가 그물치는 자의 손에서 벗어나는 것 같이 스스로 구원하라 -잠언 6:5

boardholic의 이미지

많은 도움 되었습니다.
감사합니다.^^

나에게 있어 한계란 없다.
무한한 꿈을향해 나아간다.

나에게 있어 한계란 없다.
무한한 꿈을향해 나아간다.

j0hnch01의 이미지

안녕하세요?

저도 비슷한 궁금증이 있는데요;

저같은 경우는 Cygwin에서는 eminency님이 말씀하신 대로 동작을 하는데 반해

Linux환경에서는 ./ads120 과 source ads120 모두 동일한 동작을 합니다.
즉 Linux 하에서는 ./ads120을 해도 현재 쉘의 환경변수가 잡힙니다.

Linux와 Cygwin의 차이는 무엇인가요?

( 참고로 저는 csh을 사용 합니다. )

hys545의 이미지

일반적으로 사용하는건 bash입니다
cygwin도 기본적으로는 bash
그런데 csh에선 source나 ./나ㅣ 같은 일 하는가봅니다.

즐린

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.