프로그램 아규먼트로 *가 들어갔을때..

litnsio2의 이미지

우선.. 갑자기 생각이 안나네요. *.txt 라고 할때 '*'를 지칭하는 명칭이 있었는데 기억이..-_-;;

암튼.. 프로그램에 전달인자를 주고, 전달인자에 맞게 적절한 동작을 하는 프로그램을 만들고 있습니다.
윈도와 *nix 용으로 만들었는데, 전달인자에 있는 '*'를 해석하는 방법이 각각 좀 다른것 같네요.

먼저, 윈도우의 경우 예를들어 다음과 같은 아규먼트를 주었을 때

myapp -op1 val1 -op2 val2 ... *.dat

main 안의 argv배열의 각 배열에는

argv[0] = myapp
argv[1] = -op1
argv[2] = val1
...
argv[n] = *.dat

와 같이 전달된 텍스트 값이 그대로 들어가게 됩니다. 허나 리눅스에서는 (unix 에서는 아직 테스트해보지 않았습니다), 다음과 같이 들어가네요.

argv[0] = myapp
argv[1] = -op1
argv[2] = val1
argv[n] = a00.dat
argv[n] = a01.dat
argv[n] = a02.dat
...

즉 "*.dat" 패턴에 맞는 파일이름들이 전달인자로 치환되어 들어가더군요 (쉘에 따라 다르지 않을까 하고 기본쉘인 bash와 ksh에서 테스트해봤습니다). 제 생각에는 OS 단에서 프로그램을 구동시킬 때 자동으로 아규먼트 치환과정이 있는 것 같은데 리눅스에서도 윈도에서와 같이 그냥 "*.dat"라는 텍스트 자체를 프로그램으로 전달시킬 수 있는 방법이 없을까요? 만약 방법이 없다면.. 로직이 많이 바뀔듯 해서요. ㅠㅠ

lifthrasiir의 이미지

생각하신 게 맞습니다. *를 그대로 올리려면 작은 따옴표로 묶으세요. (myapp -op1 val1 -op2 val2 ... '*.dat' 식으로)

gamdora의 이미지

이야······

Windows와 *NIX는 저런 사소한 부분에서까지 다르군요.

newman73의 이미지

* 및 ?는 wildcard character라고 하죠.
*는 길이 상관없이 아무 character가 올 수 있고,
?는 꼭 한자의 아무 character를 의미하죠.
------------------------------------------------------------
If you do not expect the unexpected, you will not find it;
for it is hard to be sought out, and difficult. [Heraclitus]

------------------------------------------------------------
If you do not expect the unexpected, you will not find it;
for it is hard to be sought out, and difficult. [Heraclitus]

blueiur의 이미지

프로그램 상에서는 동일하게 동작할겁니다.
쉘이 * <- 와일드 카드에 대한 해석을 해서 프로그램에 넘겨주기 때문에 다른게 아닐까 생각되네요.

klyx의 이미지

윈도우에서도, 리눅스에서도 파일명에는 *를 못쓰지 않나요? 그러니 파일명에 *가 들어가면 와일드카드일텐데, 그럼 blueiur님 말씀대로 쉘에서 와일드카드를 해석해서 넘겨주든, 프로그램내에서 *이 넘어오면 와일드카드로 해석해서 읽어오든, 결과는 같을텐데, 로직이 바뀔필요가 있나요...?

댓글 달기

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