昨天自行领悟了 Linux 的传送门技术....

2014-08-08 15:03:15 +08:00
 MarioLuisGarcia
why I need a teleport?
If you always need to send files to a particular directory, you'll need it.


How to use the teleport?
Pass the items to the [-|-] (it's a door!). Pong! They are on the moon now.
Or: teleport file1 file2 file3 ... file42

How to make the teleport:
1. make a file in anywhere named teleport.sh
2. type in: mv $* /path/to/destination/assume/it_is/moon
3. go home directory, edit your .bashrc
4. put this alias command in it: alias teleport='sh /path/where/you/put/teleport.sh'
5. execute command: . .bashrc
6. Done!

May you enjoy your teleport~
4480 次点击
所在节点    分享发现
15 条回复
oohusl
2014-08-08 15:43:46 +08:00
艹 hao gao duan de yang zi
pfitseng
2014-08-08 15:46:59 +08:00
我忍不住给你32个赞。。。
nicai000
2014-08-08 15:50:59 +08:00
啊? 一个简单到爆意义不大的alias被蹩脚地写成了脚本? 不过看起来很高级的样子啊难道是我没懂?
xiiing
2014-08-08 15:59:17 +08:00
rsync是不是更好一点,如果文件较多
MarioLuisGarcia
2014-08-08 16:24:32 +08:00
@nicai000 用alias如何move任意个文件到某个地方,求教。很显然我是没有领悟你知道的那种方法,然后才使用这种方法的。
nicai000
2014-08-08 16:28:47 +08:00
@MarioLuisGarcia alias teleport='mv -t /path/destination/'

或者写成函数

teleport() {
mv $* /path/destination/
}
Doubear
2014-08-08 17:07:04 +08:00
Fuck ! My english is very pool !
Youmu
2014-08-08 17:18:07 +08:00
233, 不忍直视啊。
iptux
2014-08-08 18:10:27 +08:00
1. .sh 不以 #! 作为第一行么?
2. 正确的引用命令行参数的不是 "$@" 么?
3. 不做参数检查么?

MarioLuisGarcia
2014-08-08 18:20:19 +08:00
@iptux
1.从规范的角度而言是应该加shebang的,不过bash能自动识别就没加了
2.昨天查找命令的时候有看到一个stackoverflow上讨论$@和$*的,但$*能用,就没看$@的说明了
3.传送门只管传,不管来的是小猫,小狗还是地球。。

另,借这宝地,向你请教一个问题,感觉你应该知道怎么解决。
在shell脚本里如何表示第二个参数到第无限个参数?
rrfeng
2014-08-08 18:28:21 +08:00
@MarioLuisGarcia
$2- $n = shift;$@
MarioLuisGarcia
2014-08-08 18:32:42 +08:00
@rrfeng 看来还是得看看$@啊
MarioLuisGarcia
2014-08-08 18:35:34 +08:00
@rrfeng teleport能传参数之后就可以环游太阳系了!
MarioLuisGarcia
2014-08-08 18:45:34 +08:00
@iptux 仔细看了下, $* 是把所有参数当成一个argument, $@是把所有参数当成多个argument, 在这儿$*和$@都行。

但是如果要支持往teleport里传参数旅行到其他行星的话,是需要用到$@了。
br9852000
2014-08-09 23:07:24 +08:00
我怎么感觉好无聊啊!

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/126778

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX