gcc 컴파일러를 리눅스 쉘 프로그램으로 사용할때 오류

jsw5514의 이미지

쉘 프로그래밍 코드는 다음과 같습니다.

#!/bin/bash
#fun_gcc.sh
fun_gcc()
{
    gcc -o $1 $1.c
}
fun_gcc $1

실행한 명령어는
fun_gcc.sh hello
였고 에러메세지는 다음과 같습니다.

./fun_gcc.sh: 줄 5: hello: 명령어를 찾을 수 없음
gcc: error: .c: 그런 파일이나 디렉터리가 없습니다
gcc: fatal error: no input files
compilation terminated.

PATH에 .은 있고 같은 디렉터리 내에 hello.c 파일이 있습니다.
어느 부분에 문제가 있을까요...

세벌의 이미지

ls -l 결과를 보여주셔요.

jsw5514의 이미지

합계 8
-rwxr--r-- 1 ce20a039 student 68 5월 31 14:04 fun_gcc.sh
-rw-r--r-- 1 ce20a039 student 68 5월 31 14:00 hello.c

ymir의 이미지

정말로 위 스크립트를 실행했을 때 그런 에러 메시지가 나온다고요?
5 번째 줄은 gcc -o $1 $1.c 인데, 여기에서는 어떻게 해도 hello 명령어를 찾을 수 없다는 에러가 나올 수 없습니다.

만약 첨부한 에러 메시지처럼 나오려면, 5번째 줄에 $1 만 있고, 그 다음에 gcc -o $1 .c 와 같은 식으로 나와야 합니다.
도대체 어떤 꼼수를 써야 명령어 한 줄로 그런 효과를 낼 수 있을지 짐작도 안 되네요.

뭔가 스크립트와 에러 메시지가 맞지 않는것 같습니다.

일단 bash -x ./fun_gcc.sh hello 와 같이 -x 옵션(디버깅)을 주고 실행해 보세요.

만약 실행할 때, ./fun_gcc.sh 와 같이 ./ 을 넣지 않고, 그냥 fun_gcc.sh 로 실행했다면, PATH 상 어딘가에 다른 버전의 fun_gcc.sh 가 있을 가능성도 있습니다.
which fun_gcc.sh 나 whereis fun_gcc.sh 로 한 번 찾아 보세요.

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

jsw5514의 이미지

터미널을 두개 열어서 한 터미널에서 emacs를 실행하여 스크립트를 작성하여 저장하고 다른쪽 터미널에서 실행 시켰었는데 뭔가 문제가 있었는지 emacs로 작성한 스크립트를 한쪽 터미널에서 저장했는데도 다른쪽 터미널에 반영이 안 됐었습니다. 스크립트와 오류메세지가 맞지 않는다고 하셔서 실행하는 쪽 터미널에서 cat 명령어로 직접 열어보고서야 알았네요. 자세하게 알려주시고 도와주셔서 감사합니다.

댓글 달기

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