[Q] 쉘 스크립트 잘 아시는분.....

익명 사용자의 이미지

저는 지금 리눅스 과정을 배우는 학생입니다.
오늘 쉘 스크립트를 배우면서 이상한 점이 있어 이렇게 글을 쓰네요
아래와 같이 test.sh 를 작성을 하여 실행해 보면
1.txt 2.txt 9.txt 란 값을 출력합니다.
저는 1-9로 시작하는 목록을 보여달라고 한적이 없는데 이녀석은
위와 같은 결과를 보여 주는군요.
저희 강사님 이야기로는 정큐표현식때문이라고만 하시는데..
저는 더 자세히 알수 있을까 해서 이렇게 글을 쓰네요
꼭좀 알려주세요.
+---------------------------------+
#!/bin/sh

test() {
echo $1
}

test "[1-9]*"
+---------------------------------+
test.sh를 실행한 디렉토리내의 화일 목록은 아래와 같습니다.
1.txt 2.txt test.sh 9.txt sample.txt

익명 사용자의 이미지

+---------------------------------+
#!/bin/sh // 사용하고 있는 쉘이 있는 위치를 지정.

test() { // 함수 정의부이겠죠?
echo $1 // 문제의 그 부분입니다. 함수의 인자를
} // 출력해주는 부분입니다.

test "[1-9]*" //함수의 argument로 넘어가는 값
+---------------------------------+

차근 차근 설명을 드리자면여..

우선 test() 함수는 echo문장을 이용해서 $1을 출력해주는 함수이네요.
$1 의 의미는 첫번째 argument를 의미한다는 것 아시겟죠?
$1은 변수입니다. 즉 변한다는 의미겟죠??
( 여기 "[1-9]*"부분이 변합니당. )

아랫부분에 있는.

test "[1-9]*"

이 부분에서 test()함수에 argument를 넘겨주는 부분입니다.
정규 표현식 중에서.

[1-9] 이 부분은 1또는 2또는... 9로 시작하는 녀석을 의미하고요..

*는 생략문자인거 아시죠??

( ls *.txt <= 요로코롬 치면.. 모든 .txt파일들이 출력되죠..
변수 이름에는 상관없이 확장자가 .txt인 파일들..
)

즉 님 디렉토리에 있는 파일들이
1.txt
2.txt
.
.
.
9.txt
파일들이 잇엇다는 이야기 이겠죵..
숫자로 시작하는 파일들이..
그래서 그녀석들이 출력된겁니당.
도움 되셨길.. ^^

댓글 달기

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