[완료] bash에서 조건에 맞는 내용의 색을 변경하기

artop0420의 이미지

bash에서 ls를 친 후에 특정파일의 용량이
일정 수치를 넘어서면 해당파일을 리스트 보여줄 때 빨간색으로 변경시키는 스크립트를 짜는 중입니다만.
쌩뚱맞게 오류 나네요...ㅠ_ㅠ
하다 안되서 배열을 생각했는데
파일 갯수가 많으면 배열이....ㅎㄷㄷ
그래서 배열쓰지 않고 간단하게 하려고 일단 짰는데 안되네요....으허허허허허
어떻게 짜면 좋을까요?

#!/bin/bash
 
red=$(tput setaf 1)
blue=$(tput setaf 4)
black=$(tput setaf 0)
 
lss=$(ls -l | awk '{print $5}')
 
if ["$lss" -eq 1024 ]; then
        echo $red $lss $black
else
        echo $black $lss
fi
익명 사용자의 이미지

만드셔도 유용하게 쓰실수 있을까요...
세로로 1줄로 나올텐데.....

ls 처럼 파일 이름 길이를 고려해서 정렬해서 보여줄려면
상당한 노력이 들어갈것 같아요.(셸 스크립트 만으로는)

artop0420의 이미지

고객사의 요청인지라...ㅋㅋㅋ
하다 안되면 안된다고 기능을 빼려구여;;;;
첨에는 vi에 색 들어간거 보고 쉘 스크립트로 이거대로 만들어 달라는 거
칼 같이 짤랐드랬죠.....ㅎㅎ

--- 나는요? ---

리눅스와 솔라리스 그리고 윈도우의 껍데기만 맛보고 있습니다.

bacon의 이미지

예외 처리를 좀더 하긴해야겠지만... 이런걸 원하는 겁니까?

#!/bin/bash
red=$(tput setaf 1)
nocolor=$(tput sgr0)
 
for file in *
do
     size=$(stat -c%s "$file")
     if [ $size -gt 1024 ]; then
          printf "%s %16d %s %s\n" $red $size $file $nocolor
     else
          printf "%16d %s\n" $size $file
     fi
done
artop0420의 이미지

ㅎㅎㅎ 아웃풋이 요청받은 값과 일치하네요..ㅎㅎ
아, 글구 오늘 stat라는 명령어를 첨 알았네요..ㅎㅎ
감사합니다 ^^

--- 나는요? ---

리눅스와 솔라리스 그리고 윈도우의 껍데기만 맛보고 있습니다.

댓글 달기

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