2013-07-18 1 views
3

셸 스크립트에 문제가있어 도움을 받으실 수 있기를 바랍니다.
는 다음 코드의 HTML 서식을 최적화 할 : Linux busybox 셸 스크립트 html 서식

#! /bin/sh 

cat <<EOF > myfile # temporary file 
#! /bin/sh 

echo -e "Content-type: text/html; charset=iso-8859-1\n\n" 
echo -e "<html><head>\c" 
echo -e "<title></title>" 
echo -e "</head>" 
echo -e "<body>\c" 
echo -e "<p>Text</p>" 
echo -e "</body></html>" 

EOF 
chmod 777 myfile 
mount -o bind myfile myfile # mount temporary on the original myfile 
rm myfile 

나는 에코 -e 큰 따옴표를 삭제. 나는 또한 이것을 시도 :

#! /bin/sh 

cat <<EOF > myfile # temporary file 
#! /bin/sh 

echo -e ' 
<html> 
    <head> 
     <title></title> 
    </head> 
     <body> 
      <p>Text</p> 
     </body> 
</html> 
' 

EOF 
chmod 777 myfile 
mount -o bind myfile myfile # mount temporary on the original myfile 
rm myfile 

스크립트에 문제가 있습니까?
유용한 참고 사항 : 위의 코드는 .cfg 파일의 내용으로, 재부팅 할 때마다로드됩니다.
.cfg 파일은 EOF 표시 자 사이의 내용을 CGI 스크립트 인 myfile에 붙여 넣습니다.
그게 문제일까요?

+0

도움을 청한 사람들에게 감사드립니다. 혼란 스럽기 때문에 질문을 처음부터 더 분명하게해야했습니다. 문제가 해결되었습니다. –

답변

0

가 나는 마침내 해결책을 발견 :

#! /bin/sh 

cat <<EOF > myfile # temporary file 
#! /bin/sh 

echo -e "Content-type: text/html; charset=iso-8859-1" 
echo -e " 
<html> 
    <head> 
     <title></title> 
    </head> 
     <body> 
      <p>Text</p> 
     </body> 
</html>\c" 

EOF 

chmod 777 myfile 
mount -o bind myfile myfile # mount temporary on the original myfile 
rm myfile 

BusyBox라는 쉘이 제대로 vi 편집기에 붙여 넣은 탭이 표시되지 않았습니다를, 그래서 나는 set : noai를 사용했다.
세트 : noai는 탭 문제를 해결했지만 html 코드 다음에이 여분의 행이있었습니다.
이 해결 방법은 \ c 이스케이프 문자를 사용하고 있습니다.
누군가가 더 좋은 답변을 가지고 있다면 언제든지 게시 해주십시오.

0

에코 -e 및 견적에 대한 필요가 없습니다,

cat <<eof> shellhtml.htm 
<html> 
</html> 
eof 

이 작동합니다.

0

매우 근접 :-) echo은 필요하지 않습니다.

#! /bin/sh 
cat <<EOF > myfile 
<html> 
    <head> 
    <title></title> 
    </head> 
     <body> 
     <p>Text</p> 
     </body> 
</html> 
EOF 
0

상단에 #!/빈/쉬를 추가하고 에코 E로 시작하는 라인, 및 EOF 전에 작은 따옴표로 라인을 제거 할 수 있습니다. 그러면 html이 myfile에 올바르게 전달됩니다.

그래서 올바른 쉘 스크립트는 다음과 같습니다 -

#!/bin/sh 
cat <<EOF > myfile 
<html> 
<head> 
<title></title> 
</head> 
    <body> 
    <p>Text</p> 
    </body> 
</html> 
EOF 
+0

나는 이것을 시도했지만 echo와 같이 HTML 페이지에는 아무것도 표시하지 않는다. –

+0

출력은 myfile이라는 파일에 있어야합니다. 나를 위해 그것은 완벽하게 작동합니다. – Yehuda

+0

아직 작동하지 않습니다. 무엇이 문제 일 수 있습니까? 정말 이에 대한 답변이 필요합니다. –