shell脚本执行错误 $‘r‘:command not found
时间:2022-07-28
本文章向大家介绍shell脚本执行错误 $‘r‘:command not found,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
今天在Windows下编辑了一段CentOS7下编译安装ffmpeg源代码以及相关依赖软件包的编译sh脚本,直接拷贝到CentOS7下报错了:出现$’r’:command not found
的错误。
在linux上执行脚本时出现$’r’:command not found
,然而仔细检查脚本,对应行位置只是一个空行,并没有问题,那么linux为什么会将一个回车的空行报错?
原因是这样的:脚本是在window下编辑完成后上传到linux上执行的,win下的换行是回车符+换行符,也就是rn,而unix下是换行符n。linux下不识别r为回车符,所以导致每行的配置都多了个r,因此是脚本编码的问题。
在linux上执行 dos2unix 脚本名
,再次执行脚本,报错消失。如果没有安装dos2unix
这个命令,在CentOS中执行yum install dos2unix
安装,如果是Ubuntu执行apt-get install dos2unix
即可。
下面附上在CentOS7下编译安装ffmpeg以及相关依赖库的源代码的Shell
脚本,参考了Compile FFmpeg on CentOS这篇文章,其中有些依赖库的下载地址已经失效,我换成了从http://www.linuxfromscratch.org/上面下载源代码。
# install required software package
#yum install autoconf automake bzip2 bzip2-devel cmake freetype-devel gcc gcc-c++ git libtool make mercurial pkgconfig zlib-devel
mkdir ~/ffmpeg_sources
INSTALL_PATH=/usr/local
# build and install nasm
# An assembler used by some libraries. Highly recommended or your resulting build may be very slow.
cd ~/ffmpeg_sources
curl -O -L https://www.nasm.us/pub/nasm/releasebuilds/2.14.02/nasm-2.14.02.tar.bz2
tar xjvf nasm-2.14.02.tar.bz2
cd nasm-2.14.02
./autogen.sh
./configure --prefix="$INSTALL_PATH" --bindir="$INSTALL_PATH/bin"
make
make install
# build and install Yasm
# An assembler used by some libraries. Highly recommended or your resulting build may be very slow.
cd ~/ffmpeg_sources
curl -O -L https://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar xzvf yasm-1.3.0.tar.gz
cd yasm-1.3.0
./configure --prefix="$INSTALL_PATH" --bindir="$INSTALL_PATH/bin"
make
make install
# build and install libx264
# H.264 video encoder. See the H.264 Encoding Guide for more information and usage examples.
# Requires ffmpeg to be configured with --enable-gpl --enable-libx264.
cd ~/ffmpeg_sources
git clone --depth 1 https://code.videolan.org/videolan/x264.git
curl -O -L http://anduin.linuxfromscratch.org/BLFS/x264/x264-20200819.tar.xz
xz -d x264-20200819.tar.xz
tar -xvf x264-20200819.tar
mv x264-20200819 x264
cd x264
PKG_CONFIG_PATH="$INSTALL_PATH/lib/pkgconfig" ./configure --prefix="$INSTALL_PATH" --bindir="$INSTALL_PATH/bin" --enable-static
make
make install
# build and install libx265
# H.265/HEVC video encoder. See the H.265 Encoding Guide for more information and usage examples.
# Requires ffmpeg to be configured with --enable-gpl --enable-libx265.
cd ~/ffmpeg_sources
# hg clone https://bitbucket.org/multicoreware/x265
curl -O -L http://anduin.linuxfromscratch.org/BLFS/x265/x265_3.4.tar.gz
tar -xzvf x265_3.4.tar.gz
mv x265_3.4 x265
cd ~/ffmpeg_sources/x265/build/linux
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$INSTALL_PATH" -DENABLE_SHARED:bool=off ../../source
make
make install
# build and install libfdk_aac
# AAC audio encoder. See the AAC Audio Encoding Guide for more information and usage examples.
# Requires ffmpeg to be configured with --enable-libfdk_aac (and --enable-nonfree if you also included --enable-gpl).
cd ~/ffmpeg_sources
git clone --depth 1 https://github.com/mstorsjo/fdk-aac
cd fdk-aac
autoreconf -fiv
./configure --prefix="$INSTALL_PATH" --disable-shared
make
make install
# build and install libmp3lame
# MP3 audio encoder.
# Requires ffmpeg to be configured with --enable-libmp3lame.
cd ~/ffmpeg_sources
curl -O -L https://downloads.sourceforge.net/project/lame/lame/3.100/lame-3.100.tar.gz
tar xzvf lame-3.100.tar.gz
cd lame-3.100
./configure --prefix="$INSTALL_PATH" --bindir="$INSTALL_PATH/bin" --disable-shared --enable-nasm
make
make install
# build and install libopus
# Opus audio decoder and encoder.
# Requires ffmpeg to be configured with --enable-libopus.
cd ~/ffmpeg_sources
curl -O -L https://archive.mozilla.org/pub/opus/opus-1.3.1.tar.gz
tar xzvf opus-1.3.1.tar.gz
cd opus-1.3.1
./configure --prefix="$INSTALL_PATH" --disable-shared
make
make install
# libvpx
# VP8/VP9 video encoder and decoder. See the VP9 Video Encoding Guide for more information and usage examples.
# Requires ffmpeg to be configured with --enable-libvpx.
cd ~/ffmpeg_sources
# git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git
curl -O -L https://github.com/webmproject/libvpx/archive/v1.9.0/libvpx-1.9.0.tar.gz
tar xzvf libvpx-1.9.0.tar.gz
cd libvpx-1.9.0
./configure --prefix="$INSTALL_PATH" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm
make
make install
# build and install FFmpeg
cd ~/ffmpeg_sources
curl -O -L https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
tar xjvf ffmpeg-snapshot.tar.bz2
cd ffmpeg
PATH="$INSTALL_PATH/bin:$PATH" PKG_CONFIG_PATH="$INSTALL_PATH/lib/pkgconfig" ./configure
--prefix="$INSTALL_PATH"
--pkg-config-flags="--static"
--extra-cflags="-I$INSTALL_PATH/include"
--extra-ldflags="-L$INSTALL_PATH/lib"
--extra-libs=-lpthread
--extra-libs=-lm
--bindir="$INSTALL_PATH/bin"
--enable-gpl
--enable-libfdk_aac
--enable-libfreetype
--enable-libmp3lame
--enable-libopus
--enable-libvpx
--enable-libx264
--enable-libx265
--enable-nonfree
make
make install
hash -d ffmpeg
注意:编译安装ffmpeg源代码要以root
或者超级用户权限执行,并chmod +x build_ffmpeg_all.sh
为脚本添加可执行权限运行:
sh build_ffmpeg_all.sh
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Linux安装Jenkins步骤及各种问题解决(页面访问初始化密码)
- 解决Ubuntu19 安装Theano问题
- centos7 esxi6.7模板实际应用详解
- Centos8搭建本地Web服务器的实现步骤
- 总结Linux 6种日志查看方法
- Ubuntu18.04一次性升级Python所有库的方法步骤
- linux下php安装xml扩展的详细步骤
- 查看linux文件的命令详解
- 解决Linux+Apache服务器URL区分大小写问题
- Centos8(最小化安装)全新安装Python3.8+pip的方法教程
- 使用 Linux seq 命令生成数字序列(推荐)
- CentOS 7上为PHP5安装suPHP的方法(彭哥)
- Linux修改主机名命令详解
- 在CentOS 7.2上安装SuPHP的详细方法
- centos6-7 yum安装php的方法(推荐)