我有以下文件:
<CamcorderProfiles cameraId="0">
<EncoderProfile quality="720p" fileFormat="mp4" duration="30">
<Video codec="h264"
bitRate="8000000"
width="1280"
height="720"
frameRate="30" />
<Audio codec="aac"
bitRate="96000"
sampleRate="48000"
channels="1" />
</EncoderProfile>
<EncoderProfile quality="1080p" fileFormat="mp4" duration="30">
<Video codec="h264"
bitRate="12000000"
width="1920"
height="1080"
frameRate="30" />
<Audio codec="aac"
bitRate="96000"
sampleRate="48000"
channels="1" />
</EncoderProfile>
</CamcorderProfiles>
<CamcorderProfiles cameraId="1">
<EncoderProfile quality="720p" fileFormat="mp4" duration="30">
<Video codec="h264"
bitRate="8000000"
width="1280"
height="720"
frameRate="30" />
<Audio codec="aac"
bitRate="96000"
sampleRate="48000"
channels="1" />
</EncoderProfile>
<EncoderProfile quality="1080p" fileFormat="mp4" duration="30">
<Video codec="h264"
bitRate="12000000"
width="1920"
height="1080"
frameRate="30" />
<Audio codec="aac"
bitRate="96000"
sampleRate="48000"
channels="1" />
</EncoderProfile>
</CamcorderProfiles>
这是我的代码:
camerastart=$(sed -n '{/<CamcorderProfiles cameraId="0">/=}' $file)
cameraend=$(sed -n $camerastart',$ {/<\/CamcorderProfiles>/=}' $file)
camera1080pstart=$(sed -n $camerastart','$cameraend' {/<EncoderProfile quality="1080p" fileFormat="mp4" duration="30">/=}' $file)
当我打印变量时,除了camera1080p_start之外,我得到了正确的行号,它出现了空白。
camerastart = 3
cameraend = 29
camera1080pstart =
如果我将代码的第一行更改为cameraId="1"
,那么我确实会得到适合这种情况的结果。
camerastart = 31
cameraend = 57
camera1080pstart = 45
如果我更改代码以便硬编码前两个变量,我会得到正确的17
camera1080pstart 输出。
camerastart="3"
cameraend="29"
camera1080pstart=$(sed -n $camerastart','$cameraend' {/<EncoderProfile quality="1080p" fileFormat="mp4" duration="30">/=}' $file)
有谁知道发生了什么?