前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Linux-shell 脚本

Linux-shell 脚本

原创
作者头像
用户10412487
发布2023-04-04 21:56:30
1.6K0
发布2023-04-04 21:56:30
举报
文章被收录于专栏:生信技能树-R生信技能树-R

vim编辑器 复习pic1

pic1
pic1

·shell脚本为了之后可以看出使用shell写的后面加上后缀 .sh

shell脚本解释器(shebang) pic2

pic2
pic2

shebang扩展:如何解决不同的平台或者不同的设备下的差异? shebang的通用写法:

• #!/usr/bin/env bash #用env调用

• #!/usr/bin/env python

• #!/usr/bin/env Rscript

env的位置相对固定, 让env去调用当前环境下的编译器

代码语言:txt
复制
(base) Mar402 20:35:03 ~
$ which Rscript
/usr/bin/Rscript
(base) Mar402 20:35:23 ~
$ conda activate R4
(R4) Mar402 20:35:44 ~ #在不同的环境下 Rscript不一样
$ which Rscript
/trainee/Mar402/miniconda3/envs/R4/bin/Rscript
(R4) Mar402 20:39:33 ~
$ conda activate RNA
(RNA) Mar402 20:39:49 ~
$ echo $PATH | tr ':' '\n'
/trainee/Mar402/bin
~/bin
/trainee/Mar402/miniconda3/envs/RNA/bin
/trainee/Mar402/miniconda3/condabin
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
/usr/local/games
/snap/bin #不同环境中调用不同的内容,是因为conda已经将PATH改了

想把脚本当成命令使用 (满足三个条件)

代码语言:txt
复制
(R4) Mar402 21:01:29 ~
$ vim file1.sh #条件1 存在这个文件
(R4) Mar402 21:05:26 ~
$ bash file1.sh
hi!
(R4) Mar402 21:05:39 ~
$ ll -thr file1.sh
-rw-rw-r-- 1 Mar402 Mar402 31 Apr  4 21:05 file1.sh
(R4) Mar402 21:06:35 ~
$ chmod u+x file1.sh #条件二 添加权限
(R4) Mar402 21:06:42 ~
$ ll -thr file1.sh
-rwxrw-r-- 1 Mar402 Mar402 31 Apr  4 21:05 file1.sh*
(R4) Mar402 21:06:51 ~
$ mv file1.sh* bin/ #条件三移到PATH可以搜到的范围
(R4) Mar402 21:07:34 ~
$ ls bin
ace2sam                                 hisatgenotype_build_genome.py
AUTHORS                                 hisatgenotype_extract_reads.py
blast2sam.pl                            hisatgenotype_extract_vars.py
bowtie2sam.pl                           hisatgenotype_hla_cyp.py
doc                                     hisatgenotype_locus.py
example                                 hisatgenotype_modules
export2sam.pl                           hisatgenotype.py
extract_exons.py                        hisatgenotype_scripts
extract_splice_sites.py                 interpolate_sam.pl
fasta-sanitize.pl                       LICENSE
file1.sh                                MANUAL
hisat2                                  MANUAL.markdown
hisat2-2.1.0                            maq2sam-long
hisat2-align-l                          maq2sam-short
hisat2-align-l-debug                    md5fa
hisat2-align-s                          md5sum-lite
hisat2-align-s-debug                    NEWS
hisat2-build                            novo2sam.pl
hisat2-build-l                          plot-ampliconstats
hisat2-build-l-debug                    plot-bamstats
hisat2-build-s                          psl2sam.pl
hisat2-build-s-debug                    sam2vcf.pl
hisat2_extract_exons.py                 samtools
hisat2_extract_snps_haplotypes_UCSC.py  samtools.pl
hisat2_extract_snps_haplotypes_VCF.py   scripts
hisat2_extract_splice_sites.py          seq_cache_populate.pl
hisat2-inspect                          soap2sam.pl
hisat2-inspect-l                        TUTORIAL
hisat2-inspect-l-debug                  VERSION
hisat2-inspect-s                        wgsim
hisat2-inspect-s-debug                  wgsim_eval.pl
hisat2_simulate_reads.py                zoom2sam.pl
(R4) Mar402 21:07:40 ~
$ file1.sh #直接可被当命令执行
hi!

shell 参数传递 pic3

pic3
pic3

脚本传递 pic3 上部分

脚本输出 pic3 下部分

代码语言:txt
复制
(R4) Mar402 21:15:54 ~
$ bash ~/bin/file1.sh 1>test.log 2>&1

保存输出脚本输出(log)实例 pic4

建议第四种

第四种对的运行和错的运行都保存了,而且有上下文

pic4
pic4

任务提交(重点)pic5

pic5
pic5
pic5-2
pic5-2

其他编程课看ppt

超牛学习链接

https://wangdoc.com/bash/

https://wizardforcel.gitbooks.io/vbird-linux-basic-4e/content/104.html

----来自生信技能树----

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
作者已关闭评论
0 条评论
热度
最新
推荐阅读
目录
  • vim编辑器 复习pic1
  • shell脚本解释器(shebang) pic2
  • 想把脚本当成命令使用 (满足三个条件)
  • shell 参数传递 pic3
  • 脚本传递 pic3 上部分
  • 脚本输出 pic3 下部分
  • 任务提交(重点)pic5
  • 其他编程课看ppt
  • 超牛学习链接
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档