해당 문자열을 포함하는 줄이 아닌 이 파일 httpd.conf
을 찾고 EnableSendfile
싶지만 줄이 "#"(주석 처리 된 줄이 아님)로 시작하는 경우 값을 off로 재설정하고 싶습니다.
나는 이것을 생각해 내려고 노력했다. (저는 bash 언어의 초보자입니다) 작동하지 않습니다.
검색 및 바꾸기 명령에서 변수를 사용하고 싶습니다. 나중에 배열 항목을 사용하여 키와 값을 반복 할 것이므로 일반 문자열 대신 변수를 사용해야합니다.
미리 도움을 주셔서 감사합니다!
#!/bin/bash
SEARCH="EnableSendfile"
FILEPATH="/root/scripts/httpd.conf"
REPLACE="off"
if grep -Fq $SEARCH $FILEPATH
then
line_string=`sed -n '/^EnableSendfile/p' $FILEPATH`
result_string="${line_string/(^[^#]\w*)(?:\s(\w+))?$/$REPLACE}"
echo $result_string
else
echo "not found"
fi
#
# EnableMMAP and EnableSendfile: On systems that support it,
# memory-mapping or the sendfile syscall may be used to deliver
# files. This usually improves server performance, but must
# be turned off when serving from networked-mounted
# filesystems or if support for these functions is otherwise
# broken on your system.
# Defaults if commented: EnableMMAP On, EnableSendfile Off
#
#EnableMMAP off
EnableSendfile on
#EnableSendfile on
# Supplemental configuration
#
# Load config files in the "/etc/httpd/conf.d" directory, if any.
IncludeOptional conf.d/*.conf
사용 sed
:
sed 's/^EnableSendfile on/EnableSendfile off/'
^
라인의 시작 부분에 특수 문자 일치하므로 명령은로 시작하는 라인을 변경하지 않습니다 #
.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다