내가sed 명령 줄에서 변수를 사용하는 방법은 무엇입니까?
# some other configuration settings
.....
wrapper.java.classpath.1=/opt/project/services/wrapper.jar
wrapper.java.classpath.2=/opt/project/RealTimeServer/RTEServer.jar
wrapper.java.classpath.3=/opt/project/mysql-connector-java-5.1.39-bin.jar
.....
# some other configuration settings
을 가지고이 구성 파일을 가지고 내가이
# some other configuration settings
.....
wrapper.java.classpath.1=/opt/project/services/wrapper.jar
wrapper.java.classpath.2=/opt/project/RealTimeServer/RTEServer.jar
wrapper.java.classpath.3=/opt/project/mysql-connector-java-5.1.39-bin.jar
wrapper.java.classpath.4=/opt/project/RealTimeServer/some_other.jar
.....
# some other configuration settings
같이 할 그래서 나는이 방법
를 호출#!/bin/bash
CONF_FILE=$1
JAR_FILE=$2
DIR=$3
# Get the last wrapper.java.classpath.N=/some_path line
CLASSPATH=`awk '/classpath/ {aline=$0} END{print aline}' $CONF_FILE`
echo $CLASSPATH
# Get the left side of the equation
IFS='=' read -ra LS <<< "$CLASSPATH"
# Get the value of N
NUM=${LS##*\.}
# Increment by 1
NUM=$((NUM+1))
echo $NUM
NEW_LINE="wrapper.java.classpath.$NUM=$DIR/$JAR_FILE"
echo $NEW_LINE
# Append classpath line to conf file
sed "/$CLASSPATH/a \\${NEW_LINE}" $CONF_FILE
이 bash 쉘을 썼다
./append_classpath.sh some_file.conf some_other.jar /opt/project/RealTimeServer
하지만 얻을 수
sed: -e expression #1, char 28: unknown command: `o'
무엇 거대한되지 않으면 괜찮을 여기에 변수가 있습니까? – heemayl
우리에게 모든 정보를주십시오. 테스트 파일, 변수 및 사용중인 OS와 쉘 –
어둠 속에서 그냥 쐈다 : '$ {some_string}'사용해보기. $는 변수 이름의 첫 글자 만 보입니다. $ {some_line}과 동일합니다. – steffen