57872
unxzコマンドを.sh file内から実行する際に、permission diniedエラー(以下)が表示されコマンドを実行できない。

```

    unxz: /Users/＊＊＊/mecab-ipadic-neologd/libexec/../build/mecab-ipadic-2.7.0-20070801-neologd-20190826/mecab-user-dict-seed.20190826.csv.xz: Permission denied
    
```

補足として直接そのxzファイルにterminalからunxzコマンドを実行した際は、問題なく解凍された。

## やったこと

  * shファイルとxzファイル両方の権限を777にしての実行
  * sudoコマンドでの実行
  * rootユーザに切り替えての実行

## 実行環境

macOS Mojave 10.14.6  
コマンドシェル：zsh

## log

```

    > ./bin/install-mecab-ipadic-neologd -n -a
    [install-mecab-ipadic-NEologd] : Start..
    [install-mecab-ipadic-NEologd] : Check the existance of libraries
    [install-mecab-ipadic-NEologd] :     find => ok
    [install-mecab-ipadic-NEologd] :     sort => ok
    [install-mecab-ipadic-NEologd] :     head => ok
    [install-mecab-ipadic-NEologd] :     cut => ok
    [install-mecab-ipadic-NEologd] :     egrep => ok
    [install-mecab-ipadic-NEologd] :     mecab => ok
    [install-mecab-ipadic-NEologd] :     mecab-config => ok
    [install-mecab-ipadic-NEologd] :     make => ok
    [install-mecab-ipadic-NEologd] :     curl => ok
    [install-mecab-ipadic-NEologd] :     sed => ok
    [install-mecab-ipadic-NEologd] :     cat => ok
    [install-mecab-ipadic-NEologd] :     diff => ok
    [install-mecab-ipadic-NEologd] :     tar => ok
    [install-mecab-ipadic-NEologd] :     unxz => ok
    [install-mecab-ipadic-NEologd] :     xargs => ok
    [install-mecab-ipadic-NEologd] :     grep => ok
    [install-mecab-ipadic-NEologd] :     iconv => ok
    [install-mecab-ipadic-NEologd] :     patch => ok
    [install-mecab-ipadic-NEologd] :     which => ok
    [install-mecab-ipadic-NEologd] :     file => ok
    [install-mecab-ipadic-NEologd] :     openssl => ok
    [install-mecab-ipadic-NEologd] :     awk => ok
    
    [install-mecab-ipadic-NEologd] : mecab-ipadic-NEologd is already up-to-date
    
    [install-mecab-ipadic-NEologd] : mecab-ipadic-NEologd will be install to /usr/local/lib/mecab/dic/mecab-ipadic-neologd
    
    [install-mecab-ipadic-NEologd] : Make mecab-ipadic-NEologd
    [make-mecab-ipadic-NEologd] : Start..
    [make-mecab-ipadic-NEologd] : Check local seed directory
    [make-mecab-ipadic-NEologd] : Check local seed file
    [make-mecab-ipadic-NEologd] : Check local build directory
    [make-mecab-ipadic-NEologd] : create /Users/***/mecab-ipadic-neologd/libexec/../build
    [make-mecab-ipadic-NEologd] : Download original mecab-ipadic file
    [make-mecab-ipadic-NEologd] : Try to access to https://ja.osdn.net
    [make-mecab-ipadic-NEologd] : Try to download from https://ja.osdn.net/frs/g_redir.php?m=kent&f=mecab%2Fmecab-ipadic%2F2.7.0-20070801%2Fmecab-ipadic-2.7.0-20070801.tar.gz
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
      0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
    100 11.6M  100 11.6M    0     0  10.0M      0  0:00:01  0:00:01 --:--:-- 21.9M
    Hash value of /Users/***/mecab-ipadic-neologd/libexec/../build/mecab-ipadic-2.7.0-20070801.tar.gz matched
    [make-mecab-ipadic-NEologd] : Decompress original mecab-ipadic file
    x mecab-ipadic-2.7.0-20070801/
    x mecab-ipadic-2.7.0-20070801/README
    x mecab-ipadic-2.7.0-20070801/AUTHORS
    x mecab-ipadic-2.7.0-20070801/COPYING
    x mecab-ipadic-2.7.0-20070801/ChangeLog
    x mecab-ipadic-2.7.0-20070801/INSTALL
    x mecab-ipadic-2.7.0-20070801/Makefile.am
    x mecab-ipadic-2.7.0-20070801/Makefile.in
    x mecab-ipadic-2.7.0-20070801/NEWS
    x mecab-ipadic-2.7.0-20070801/aclocal.m4
    x mecab-ipadic-2.7.0-20070801/config.guess
    x mecab-ipadic-2.7.0-20070801/config.sub
    x mecab-ipadic-2.7.0-20070801/configure
    x mecab-ipadic-2.7.0-20070801/configure.in
    x mecab-ipadic-2.7.0-20070801/install-sh
    x mecab-ipadic-2.7.0-20070801/missing
    x mecab-ipadic-2.7.0-20070801/mkinstalldirs
    x mecab-ipadic-2.7.0-20070801/Adj.csv
    x mecab-ipadic-2.7.0-20070801/Adnominal.csv
    x mecab-ipadic-2.7.0-20070801/Adverb.csv
    x mecab-ipadic-2.7.0-20070801/Auxil.csv
    x mecab-ipadic-2.7.0-20070801/Conjunction.csv
    x mecab-ipadic-2.7.0-20070801/Filler.csv
    x mecab-ipadic-2.7.0-20070801/Interjection.csv
    x mecab-ipadic-2.7.0-20070801/Noun.adjv.csv
    x mecab-ipadic-2.7.0-20070801/Noun.adverbal.csv
    x mecab-ipadic-2.7.0-20070801/Noun.csv
    x mecab-ipadic-2.7.0-20070801/Noun.demonst.csv
    x mecab-ipadic-2.7.0-20070801/Noun.nai.csv
    x mecab-ipadic-2.7.0-20070801/Noun.name.csv
    x mecab-ipadic-2.7.0-20070801/Noun.number.csv
    x mecab-ipadic-2.7.0-20070801/Noun.org.csv
    x mecab-ipadic-2.7.0-20070801/Noun.others.csv
    x mecab-ipadic-2.7.0-20070801/Noun.place.csv
    x mecab-ipadic-2.7.0-20070801/Noun.proper.csv
    x mecab-ipadic-2.7.0-20070801/Noun.verbal.csv
    x mecab-ipadic-2.7.0-20070801/Others.csv
    x mecab-ipadic-2.7.0-20070801/Postp-col.csv
    x mecab-ipadic-2.7.0-20070801/Postp.csv
    x mecab-ipadic-2.7.0-20070801/Prefix.csv
    x mecab-ipadic-2.7.0-20070801/Suffix.csv
    x mecab-ipadic-2.7.0-20070801/Symbol.csv
    x mecab-ipadic-2.7.0-20070801/Verb.csv
    x mecab-ipadic-2.7.0-20070801/char.def
    x mecab-ipadic-2.7.0-20070801/feature.def
    x mecab-ipadic-2.7.0-20070801/left-id.def
    x mecab-ipadic-2.7.0-20070801/matrix.def
    x mecab-ipadic-2.7.0-20070801/pos-id.def
    x mecab-ipadic-2.7.0-20070801/rewrite.def
    x mecab-ipadic-2.7.0-20070801/right-id.def
    x mecab-ipadic-2.7.0-20070801/unk.def
    x mecab-ipadic-2.7.0-20070801/dicrc
    x mecab-ipadic-2.7.0-20070801/RESULT
    [make-mecab-ipadic-NEologd] : Configure custom system dictionary on /Users/***/mecab-ipadic-neologd/libexec/../build/mecab-ipadic-2.7.0-20070801-neologd-20190826
    checking for a BSD-compatible install... /usr/bin/install -c
    checking whether build environment is sane... yes
    checking whether make sets $(MAKE)... yes
    checking for working aclocal-1.4... missing
    checking for working autoconf... found
    checking for working automake-1.4... missing
    checking for working autoheader... found
    checking for working makeinfo... found
    checking for a BSD-compatible install... /usr/bin/install -c
    checking for mecab-config... /usr/local/bin/mecab-config
    configure: creating ./config.status
    config.status: creating Makefile
    [make-mecab-ipadic-NEologd] : Encode the character encoding of system dictionary resources from EUC_JP to UTF-8
    ./../../libexec/iconv_euc_to_utf8.sh ./Noun.place.csv
    ./../../libexec/iconv_euc_to_utf8.sh ./Auxil.csv
    ./../../libexec/iconv_euc_to_utf8.sh ./Noun.verbal.csv
    ./../../libexec/iconv_euc_to_utf8.sh ./Symbol.csv
    ./../../libexec/iconv_euc_to_utf8.sh ./Noun.org.csv
    ./../../libexec/iconv_euc_to_utf8.sh ./Noun.csv
    ./../../libexec/iconv_euc_to_utf8.sh ./Postp.csv
    ./../../libexec/iconv_euc_to_utf8.sh ./Adj.csv
    ./../../libexec/iconv_euc_to_utf8.sh ./Filler.csv
    ./../../libexec/iconv_euc_to_utf8.sh ./Noun.proper.csv
    ./../../libexec/iconv_euc_to_utf8.sh ./Noun.number.csv
    ./../../libexec/iconv_euc_to_utf8.sh ./Suffix.csv
    ./../../libexec/iconv_euc_to_utf8.sh ./Noun.others.csv
    ./../../libexec/iconv_euc_to_utf8.sh ./Interjection.csv
    ./../../libexec/iconv_euc_to_utf8.sh ./Noun.adjv.csv
    ./../../libexec/iconv_euc_to_utf8.sh ./Verb.csv
    ./../../libexec/iconv_euc_to_utf8.sh ./Others.csv
    ./../../libexec/iconv_euc_to_utf8.sh ./Adnominal.csv
    ./../../libexec/iconv_euc_to_utf8.sh ./Prefix.csv
    ./../../libexec/iconv_euc_to_utf8.sh ./Noun.demonst.csv
    ./../../libexec/iconv_euc_to_utf8.sh ./Adverb.csv
    ./../../libexec/iconv_euc_to_utf8.sh ./Noun.name.csv
    ./../../libexec/iconv_euc_to_utf8.sh ./Postp-col.csv
    ./../../libexec/iconv_euc_to_utf8.sh ./Conjunction.csv
    ./../../libexec/iconv_euc_to_utf8.sh ./Noun.nai.csv
    ./../../libexec/iconv_euc_to_utf8.sh ./Noun.adverbal.csv
    rm ./Noun.place.csv
    rm ./Auxil.csv
    rm ./Noun.verbal.csv
    rm ./Symbol.csv
    rm ./Noun.org.csv
    rm ./Noun.csv
    rm ./Postp.csv
    rm ./Adj.csv
    rm ./Filler.csv
    rm ./Noun.proper.csv
    rm ./Noun.number.csv
    rm ./Suffix.csv
    rm ./Noun.others.csv
    rm ./Interjection.csv
    rm ./Noun.adjv.csv
    rm ./Verb.csv
    rm ./Others.csv
    rm ./Adnominal.csv
    rm ./Prefix.csv
    rm ./Noun.demonst.csv
    rm ./Adverb.csv
    rm ./Noun.name.csv
    rm ./Postp-col.csv
    rm ./Conjunction.csv
    rm ./Noun.nai.csv
    rm ./Noun.adverbal.csv
    ./../../libexec/iconv_euc_to_utf8.sh ./rewrite.def
    ./../../libexec/iconv_euc_to_utf8.sh ./matrix.def
    ./../../libexec/iconv_euc_to_utf8.sh ./left-id.def
    ./../../libexec/iconv_euc_to_utf8.sh ./pos-id.def
    ./../../libexec/iconv_euc_to_utf8.sh ./unk.def
    ./../../libexec/iconv_euc_to_utf8.sh ./feature.def
    ./../../libexec/iconv_euc_to_utf8.sh ./right-id.def
    ./../../libexec/iconv_euc_to_utf8.sh ./char.def
    rm ./rewrite.def
    rm ./matrix.def
    rm ./left-id.def
    rm ./pos-id.def
    rm ./unk.def
    rm ./feature.def
    rm ./right-id.def
    rm ./char.def
    mv ./Noun.others.csv.utf8 ./Noun.others.csv
    mv ./Noun.number.csv.utf8 ./Noun.number.csv
    mv ./Filler.csv.utf8 ./Filler.csv
    mv ./Others.csv.utf8 ./Others.csv
    mv ./unk.def.utf8 ./unk.def
    mv ./Postp-col.csv.utf8 ./Postp-col.csv
    mv ./Adnominal.csv.utf8 ./Adnominal.csv
    mv ./Noun.verbal.csv.utf8 ./Noun.verbal.csv
    mv ./matrix.def.utf8 ./matrix.def
    mv ./Noun.csv.utf8 ./Noun.csv
    mv ./Noun.demonst.csv.utf8 ./Noun.demonst.csv
    mv ./char.def.utf8 ./char.def
    mv ./Symbol.csv.utf8 ./Symbol.csv
    mv ./Auxil.csv.utf8 ./Auxil.csv
    mv ./Noun.name.csv.utf8 ./Noun.name.csv
    mv ./feature.def.utf8 ./feature.def
    mv ./Suffix.csv.utf8 ./Suffix.csv
    mv ./Adverb.csv.utf8 ./Adverb.csv
    mv ./Conjunction.csv.utf8 ./Conjunction.csv
    mv ./pos-id.def.utf8 ./pos-id.def
    mv ./Postp.csv.utf8 ./Postp.csv
    mv ./right-id.def.utf8 ./right-id.def
    mv ./Noun.nai.csv.utf8 ./Noun.nai.csv
    mv ./Interjection.csv.utf8 ./Interjection.csv
    mv ./Prefix.csv.utf8 ./Prefix.csv
    mv ./Noun.place.csv.utf8 ./Noun.place.csv
    mv ./Noun.adjv.csv.utf8 ./Noun.adjv.csv
    mv ./rewrite.def.utf8 ./rewrite.def
    mv ./Verb.csv.utf8 ./Verb.csv
    mv ./left-id.def.utf8 ./left-id.def
    mv ./Noun.proper.csv.utf8 ./Noun.proper.csv
    mv ./Adj.csv.utf8 ./Adj.csv
    mv ./Noun.adverbal.csv.utf8 ./Noun.adverbal.csv
    mv ./Noun.org.csv.utf8 ./Noun.org.csv
    [make-mecab-ipadic-NEologd] : Fix yomigana field of IPA dictionary
    patching file Noun.csv
    patching file Noun.place.csv
    patching file Verb.csv
    patching file Noun.verbal.csv
    patching file Noun.name.csv
    patching file Noun.adverbal.csv
    patching file Noun.csv
    patching file Noun.name.csv
    patching file Noun.org.csv
    patching file Noun.others.csv
    patching file Noun.place.csv
    patching file Noun.proper.csv
    patching file Noun.verbal.csv
    patching file Prefix.csv
    patching file Suffix.csv
    patching file Noun.proper.csv
    patching file Noun.csv
    patching file Noun.name.csv
    patching file Noun.org.csv
    patching file Noun.place.csv
    patching file Noun.proper.csv
    patching file Noun.verbal.csv
    patching file Noun.name.csv
    patching file Noun.org.csv
    patching file Noun.place.csv
    patching file Noun.proper.csv
    patching file Suffix.csv
    patching file Noun.demonst.csv
    patching file Noun.csv
    patching file Noun.name.csv
    [make-mecab-ipadic-NEologd] : Copy user dictionary resource
    unxz: /Users/***/mecab-ipadic-neologd/libexec/../build/mecab-ipadic-2.7.0-20070801-neologd-20190826/mecab-user-dict-seed.20190826.csv.xz: Permission denied
    
```

## 実行コマンド

```

    ./bin/install-mecab-ipadic-neologd -n -a
    
```

(-a抜きで実行したら、mkdirのコマンドの権限がないということでpermission deniedがでました)  
やはりシェルスクリプト内で実行されるコマンドに権限がないようです。

# 追記

```

    $ ./bin/install-mecab-ipadic-neologd -n -a
    
```

~~実行時に、毎度onlineでファイルを取得するようで、その前にディレクトリの権限を再帰的に変更したとしても新たなファイルでは書き込み権限なしで保存されているため、permission
error がおこるようです。。~~

と思いましたが、解凍したいファイル'mecab-user-dict-seed.20190826.csv.xz'の作成時の権限は

```

    -rw-r--r--
    
```

であり、このままユーザ権限でunxzコマンドが実行できたので、解凍したいファイルの権限は関係ないように思われます。  
また、unxzを行うshファイルの権限を777に変更しても、結果は同じでした。

sh file は[こちら](https://github.com/neologd/mecab-ipadic-neologd)で参照できるため、error
logを記載することにしました。

  * set -x 追加後

```

    [make-mecab-ipadic-NEologd] : Copy user dictionary resource
    + SEED_FILE_NAME=mecab-user-dict-seed.20190826.csv
    + '[' 0 -eq 0 ']'
    + cp /Users/***/mecab-ipadic-neologd/libexec/../seed/mecab-user-dict-seed.20190826.csv.xz /Users/***/mecab-ipadic-neologd/libexec/../build/mecab-ipadic-2.7.0-20070801-neologd-20190826
    + unxz /Users/***/mecab-ipadic-neologd/libexec/../build/mecab-ipadic-2.7.0-20070801-neologd-20190826/mecab-user-dict-seed.20190826.csv.xz
    unxz: /Users/***/mecab-ipadic-neologd/libexec/../build/mecab-ipadic-2.7.0-20070801-neologd-20190826/mecab-user-dict-seed.20190826.csv.xz: Permission denied
    
```
CC BY-SA 4.0
2019-08-29T07:58:38.960
57692
2019-09-05T11:22:32.277
2019-08-30T18:35:23.453
31916
31916
question
macos shellscript
シェルスクリプト内での解凍コマンドの実行権限について
試行錯誤の結果、根本的な原因は不明ですが対応することができました。  
以下に、行った処理を記しておきます。

仕組みとして、インストール(アップデート)時に毎度(必要があれば)更新ファイルをダウンロードし、それらを一時的に保管します。  
その後、それらをbase dirにcp→unxz(解凍)という順番だったのですが、それをunxz→cpという順番にする(sh
fileを書き換える)ことで解決しました。

おそらく、 cp後のdirのパスがなにか悪影響を与えていたのだと考えられます。
CC BY-SA 4.0
2019-09-05T11:22:32.277
57872
2019-09-05T11:22:32.277
31916
57692
answer