shell script 관련..질문입니다.

irdeal의 이미지

현재 사용자는 root이고요
스크립트 개념도 부족하고 해서 연습을 하고 있는데요. wiki보면서요..

간단하게 패스 export해주는 것을 해보았는데 적용이 안되네요 왜 그럴까요? :(

export SDK=/home/irdeal/workarea/firmware
export IRRE=/home/irdeal/refference
export IRWO=/home/irdeal/workarea

이렇게 파일을 만들고요 실행권한주고 실행을 한다음에 printenv
로 확인을 해보면 환경설정에 포함이 안되있더군요 왜 그런가요?

$? 출력하면 세군데 다 0값으로 나와서 제대로 수행하는거 같은데..

좋은 하루 되세용 :) [/code]

pynoos의 이미지

실행권한을 주고 실행하면 새로운 쉘이 뜨게 되고 그 쉘에서만 적용된다음 스크립트가 종료되면 같이 사라집니다.

. 명령을 사용하세요....

또는 source 명령으로 하셔도됩니다.

익명 사용자의 이미지

shell script 내에서 정의한 환경변수들은 shell script가 실행될 동안만 유효합니다.
현재 사용중인 shell에서 shell script를 실행하면 새로운 shell이 생성되어서 실행되고 종료되기 때문입니다.

쉘 스크립트를 실행하는 방법은 다음과 같은 방법이 있습니다.

# source myscript.sh
# . myscript.sh

# bash myscript.sh
# chmod 755 myscript.sh;./myscript.sh

위의 2가지 실행스타일과 밑의 두가지 스타일은 각기 동작이 틀립니다.

위의 2가지 스타일의 경우 새로운 쉘이 생성되지 않고 실행됩니다.
따라서 스크립트내에서 정의한 환경변수들이 유지가 될 수 있습니다.
하지만 밑의 두가지 스타일의 경우 새로운 쉘이 생성되어서 스크립트가 실행되므로 스크립트내에서 정의한 환경변수들이 스크립트가 종료된 다음에 유지되지 않습니다.

또 하나 말하자면 위의 두가지 스타일은 새로운 쉘에서 실행되지 않고 현재 쉘에서 실행되므로 스크립트내에서 "exit 0"과 같은 코드를 사용하게 되면 현재 쉘이 닫혀버리게 됩니다.

irdeal의 이미지

명쾌한 답변에 감사드립니다. :D

제가 쉘스크립트에 대한 기본 개념이 부족했었네요.

또 하나 배워갑니다.

May The Force Be With You
irdeal

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.