좋아요, 그래서 변수 값을 사용하여 해당 변수 값을 inorder 변수 값으로 사용하려고합니다.변수 값을 사용하여 변수 값 사용
그래서, 내는 script
메시지로 $1
소요되며, 다음으로 그것을 인쇄 할 수있는 컬러로 $2
걸립니다.
USAGE: cecho "MESSAGE" color
그래서, 기본적으로 스크립트 포인트가 $2
이 동일 무엇 이건 $message
색을하는 것입니다
#!/bin/bash
# TAKES $1 as MSG and $2 as COLOR.
export black='echo -e "\E[30;47m"'
export red='echo -e "\E[31;47m"'
export green='echo -e "\E[32;47m"'
export yellow='echo -e "\E[33;47m"'
export blue='echo -e "\E[34;47m"'
export magenta='echo -e "\E[35;47m"'
export cyan='echo -e "\E[36;47m"'
export white='echo -e "\E[37;47m"'
# VARIABLES
export color="$2" # Set Color
export message="$1" # Set MSG
# Use $color for what variable to substitute with, so we get the echos.
# Previously tried \$$color to get $whatever_$2_was but it wouldn't get the value.
\$$color
echo "$message" # Echo Message.
tput sgr0 # Reset to normal.
이라 할 것입니다.
Anyidea 방법 중 하나
1.에서, $2
이름으로 변수의 값을 가져
또는이 script
를 작성
2 더 나은 방법은?
정확히 내가 찾고 있었고 놀랍도록 노력한 솔루션과 팁 덕분에! –