相关疑难解决方法(0)

从Bash脚本更改当前目录

是否可以从脚本更改当前目录?

我想在Bash中为目录导航创建一个实用程序.我创建了一个如下所示的测试脚本:

#!/bin/bash
cd /home/artemb
Run Code Online (Sandbox Code Playgroud)

当我从Bash shell执行脚本时,当前目录不会更改.是否可以从脚本中更改当前的shell目录?

bash environment

175
推荐指数
9
解决办法
26万
查看次数

shell脚本中的全局环境变量

如何在bash脚本中设置全局环境变量?

如果我喜欢的话

#!/bin/bash
FOO=bar
Run Code Online (Sandbox Code Playgroud)

...要么

#!/bin/bash
export FOO=bar
Run Code Online (Sandbox Code Playgroud)

... vars似乎停留在本地环境中,而我希望在脚本执行完毕后继续使用它们.

shell scripting environment-variables

81
推荐指数
3
解决办法
13万
查看次数

如何在shell脚本中运行'cd'并在脚本完成后留在那里?

我在shell脚本中使用了'更改目录'(bash)

#!/bin/bash
alias mycd='cd some_place'
mycd
pwd
Run Code Online (Sandbox Code Playgroud)

pwd打印some_place正确,但脚本完成后,我当前的工作目录不会更改.

是否可以通过脚本更改我的路径?

bash shell cd pwd

68
推荐指数
3
解决办法
6万
查看次数

使用`sh`和`source`有什么区别?

sh和之间有什么区别source

source: source filename [arguments]
    Read and execute commands from FILENAME and return.  The pathnames
    in $PATH are used to find the directory containing FILENAME.  If any
    ARGUMENTS are supplied, they become the positional parameters when
    FILENAME is executed.
Run Code Online (Sandbox Code Playgroud)

并为man sh:

NAME
       bash - GNU Bourne-Again SHell

SYNOPSIS
       bash [options] [file]

COPYRIGHT
       Bash is Copyright (C) 1989-2004 by the Free Software Foundation, Inc.

DESCRIPTION
       Bash  is  an sh-compatible command language interpreter that executes commands read …
Run Code Online (Sandbox Code Playgroud)

unix linux bash shell

52
推荐指数
3
解决办法
3万
查看次数

我的Git bash忘了我的别名.我能做什么?

我在运行Windows 7的笔记本电脑上使用最新的Git bash for Windows.当我定义我的别名时:

$ alias gitc='git commit -a'
Run Code Online (Sandbox Code Playgroud)

在会议期间一切运作良好,但如果我关闭并打开bash,我无法恢复它们.但是,保留了命令历史记录.

我该怎么办?我错过了什么?

谢谢!

git bash

48
推荐指数
4
解决办法
2万
查看次数

如何设置父进程的工作目录?

正如标题所揭示的那样,我们正在编写一个Unix风格的shell实用程序U,应该从bash调用(在大多数情况下).

究竟是如何能ü改变的bash(一般或父母)的工作目录?

PS shell实用程序chdir成功完成相同的操作,因此必须有一种实现该效果的编程方式.

linux gcc process parent working-directory

23
推荐指数
4
解决办法
9410
查看次数

将bash脚本作为源而不使用源命令运行

有没有办法将脚本标记为"作为源运行",因此您不必添加source或"." 每次命令它?也就是说,如果我写一个名为"sup"的脚本,我想称之为

sup Argument
Run Code Online (Sandbox Code Playgroud)

而不是

source sup Argument
Run Code Online (Sandbox Code Playgroud)

要么

. sup Argument
Run Code Online (Sandbox Code Playgroud)

基本上,我正在尝试cd在脚本中使用.

bash

20
推荐指数
4
解决办法
3万
查看次数

获取"VM初始化期间出错"

我有一个由Autosys作业调度程序调用的旧shell脚本.在脚本中,他们调用一个jar文件

res="`$JAVA_HOME/bin/java ....`"
echo >$res<
Run Code Online (Sandbox Code Playgroud)

我收到以下错误.

Error occurred during initialization of VM 
    java.lang.Error: Properties init: Could not determine current working directory.
Run Code Online (Sandbox Code Playgroud)

所以在shell脚本中我尝试打印当前目录,如下所示

echo "PWD:" "$PWD"    # Nothing gets printed.
echo "USER:" "$USER"  # User id is getting printed

if [ -d "/export/home/abc/" ]; then
    echo "Directory present"    # gets printed
    echo `ls -ltr`              # total 3 gets printed
    echo `cd /export/abc/def`
    echo `pwd`                  # nothing gets printed
fi
Run Code Online (Sandbox Code Playgroud)

所有类路径都在脚本本身中设置,类路径看起来很好.我没有得到这里可能存在的问题.

另请注意,此脚本由另一个脚本调用,该脚本由Autosys作业调度程序调用.

java unix linux shell solaris

17
推荐指数
2
解决办法
921
查看次数

Bash脚本更改父shell目录

我想做什么

我已经创建了一个shell脚本,我已添加到我的$ PATH中,它将下载并获取新Laravel项目的所有设置.我希望通过将终端目录更改为新项目文件夹来结束脚本.

根据我现在所理解的,它只是改变了脚本实际运行的子shell的目录.我似乎无法弄清楚如何做到这一点.任何帮助表示赞赏.谢谢!

#! /usr/bin/env bash

echo -e '\033[1;30m=========================================='

## check for a directory
if test -z "$1"; then
  echo -e ' \033[0;31m? Please provide a directory name'
  exit
fi

## check if directory already exist
if [ ! -d $1 ]; then
  mkdir $1
else
  echo -e ' \033[0;31m? The '"$1"' directory already exists'
  exit
fi

# move to directory
cd $1

## Download Laravel
echo -e ' \033[0;32m+ \033[0mDownloading Laravel...'
curl -s -L https://github.com/laravel/laravel/zipball/master > …
Run Code Online (Sandbox Code Playgroud)

unix bash shell cd

8
推荐指数
2
解决办法
1万
查看次数

在特定目录中运行`ng build`

我正在编写一个需要ng build在特定目录中运行的自动构建脚本.我的项目有以下结构:

project
? build-script
? project-client
  ? package.json
Run Code Online (Sandbox Code Playgroud)

ng build正在寻找package.json文件,但它无法在当前位置找到它.有没有办法可以直接ng build到子目录而不做一个cd(因为bash对于更改目录有点不稳定)?基本上,我只需要一种方法来告诉ng build我在我指定的目录中操作.

我已经尝试过,ng build ./project-client/但它给出的错误是"你必须在angular-cli项目中才能使用build命令"

谢谢.

bash angular-cli

8
推荐指数
3
解决办法
5508
查看次数