以下在package.json内部工作
https://github.com/facebook/react-native/issues/13198#issuecomment-302917321
"scripts": {
"postinstall": "sed -i '' 's\/#import <RCTAnimation\\/RCTValueAnimatedNode.h>\/#import \"RCTValueAnimatedNode.h\"\/' ./node_modules/react-native/Libraries/NativeAnimation/RCTNativeAnimatedNodesManager.h",
...rest scripts
}
但是,如果我将命令移至postinstall.sh
并尝试执行,则会导致错误
postinstall.sh:
sed -i '' 's\/#import <RCTAnimation\\/RCTValueAnimatedNode.h>\/#import \"RCTValueAnimatedNode.h\"\/' ./node_modules/react-native/Libraries/NativeAnimation/RCTNativeAnimatedNodesManager.h
答案 0 :(得分:1)
原始命令比原来的要复杂,导致不必要的和令人困惑的转义。
"scripts": {
"postinstall": "sed -i '' 's|#import <RCTAnimation/RCTValueAnimatedNode.h>|#import \"RCTValueAnimatedNode.h\"|' ./node_modules/react-native/Libraries/NativeAnimation/RCTNativeAnimatedNodesManager.h",
...rest scripts
}
因此提取的sed
命令应该简单地
sed -i '' 's|#import <RCTAnimation/RCTValueAnimatedNode.h>|#import "RCTValueAnimatedNode.h"|' \
./node_modules/react-native/Libraries/NativeAnimation/RCTNativeAnimatedNodesManager.h
唯一的区别是您无需在替换文本中转义"
。
顺便说一句,使用sed -i
通常意味着您只能使用流编辑器ed
所基于的文件编辑器sed
。
printf '%s\n' \
's|#import <RCTAnimation/RCTValueAnimatedNode.h>|#import "RCTValueAnimatedNode.h"|' \
'wq' |
ed ./node_modules/react-native/Libraries/NativeAnimation/RCTNativeAnimatedNodesManager.h