Bash脚本:当脚本从git bash终端运行时,subl命令不会打开文件,从windows cmd成功运行

时间:2017-04-25 03:31:42

标签: bash shell sublimetext

问题

我正在尝试编写一个Bash Shell脚本,该脚本使用一些基本的头类型信息填充文件,然后打开该文件以便在sublime中进行编辑。到目前为止,我已经编写了脚本,并且能够确认代码的行为符合预期,直到最后一行subl $filename

更新 :进一步测试发现,当$ filename变量指向git存储库时,subl命令在由脚本发出时失败但在给定目标路径的任何地方时脚本完美地执行subl命令。更令人费解的是,在指向Git repo的文件上调用subl命令在终端中工作正常???

Verison和Where Results

--- Git Bash:GNU bash,版本4.3.46(2)-release(x86_64-pc-msys)

~ $ where bash
C:\Program Files\Git\usr\bin\bash.exe
C:\Windows\System32\bash.exe


--- Sublime:Sublime Text Build 3126

$ where subl
C:\Program Files\Sublime Text 3\subl.exe

错误

  

第31行:/ c / Program Files / Sublime Text 3 / subl:Bad address

.SH

#!/usr/bin/bash
#Set your blog site's post directory here
ppath=~/Desktop/blog-sites/CPSC350-rudiment-developerblog/_posts

# Get user input
echo "Post Title: "
read title
echo "Post Categories: "
read keyw

# Process Input
ptitle=${title// /-}                            # convert spaces in title to hyphens
plc=`echo "$ptitle" | tr '[:upper:]' '[:lower:]'`   # convert title to lowercase
pdate=`date +%Y-%m-%d`                             # create date as Year-Month-Date
filename=$ppath/$pdate-$plc.markdown                  # location to create the new file in YYYY-MM-DD-filename format
touch $filename                                     # create the new blank post

# Set post YML header data and push to post file
echo "---
layout: post
title: $title
date: $pdate -0400
categories: [$keyw]
---" > $filename

# Open file in sublime
subl $filename

〜/ .bash_profile中

# Add directories to PATH variable
export PATH="/c/Program\ Files/Sublime\ Text\ 3:~/.scripts:$PATH:."

的尝试

我已经确认在脚本外部的终端中运行的每一行都没有错误地执行。我使用了UNIX样式和Windows样式$filename路径,返回相同的结果。我已经在cmd中执行了subl命令而没有错误。此外,我尝试使用subl的别名,只返回相同的错误。我也尝试使用脚本中的绝对路径调用subl.exe;用;替换31号线;
/c/Program\ Files/Sublime\ Text\ 3/subl.exe
返回相同的Bad Address错误。

任何建议都非常感谢。

更新 只是认为这有助于说明我能够工作的内容和不起作用的内容。

不起作用

使用变量$ filename = subl调用~Desktop/blog-sites/CPSC350-rudiment-developerblog/some-name.markdown#CPSC350 ...是一个git repo

作品

使用变量$ filename = subl调用~Desktop/blog-sites/some-name.markdown#不在git repo中

0 个答案:

没有答案