"cd"在shell脚本中不起作用 [英] "cd" does not work in shell script

查看:799
本文介绍了"cd"在shell脚本中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么cd在shell脚本中不起作用.如下,

I am wondering why cd does not work in shell script. It is as follows,

#!/bin/sh
cd test
mkdir $(date +%d-%mm-%Y)

运行此程序时,我无法进行cd测试

When I run this, I get can't cd to test

cd: 2: can't cd to /test

为什么会这样?

推荐答案

我遇到了同样的问题.原来问题是\ r \ n行尾.

I had the same problem. Turned out the problem was \r\n line endings.

要解决此问题,请

tr -d "\r" < oldname.sh > newname.sh

来自 http://talk.maemo.org /showthread.php?s=1cadd53b369d5408c2b9d53580a32dc4&t=67836&page=2

这篇关于"cd"在shell脚本中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆