You are not logged in.

#1 2014-04-30 18:43:22

publicus
Member
Registered: 2014-01-01
Posts: 129

[SOLVED] Unable to create a file in a script

Hello,

I'm running this script:

cat "" > $LOG_DUMP/FPGA_log.txt
echo "$RESULTS" >| $LOG_DUMP/FPGA_log.txt

And this is what I'm getting:

...
hl_script.sh: line 109: logs/2014_04_30_14_41_49/FPGA_log.txt: No such file or directory
hl_script.sh: line 111: logs/2014_04_30_14_41_49/FPGA_log.txt: No such file or directory
...

The thing about this path is that I _know_ that it exists and I'm trying to create the FPGA_log.txt file (note: I've tried touch, but got the same error.)

Last edited by publicus (2014-04-30 19:07:09)

Offline

#2 2014-04-30 18:57:14

Saint0fCloud
Member
Registered: 2009-03-31
Posts: 137

Re: [SOLVED] Unable to create a file in a script

Try setting $LOG_DUMP to an absolute path

Offline

#3 2014-04-30 19:00:50

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: [SOLVED] Unable to create a file in a script

I don't understand why you're catting an empty string to the file to create it nor have I ever seen ">|" before. Try this instead

mkdir -p "$LOG_DUMP"
echo "$RESULTS" > "$LOG_DUMP/FPGA_log.txt"

Also note that you are not using absolute paths so the paths will be relative to the directory where the script is run. Perhaps it is not trying to write to the file you intend. To check the path, use

readlink -f  "$LOG_DUMP"

My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#4 2014-04-30 19:06:39

publicus
Member
Registered: 2014-01-01
Posts: 129

Re: [SOLVED] Unable to create a file in a script

Xyne, you're right.  I was in the wrong path all along.  I didn't prefix the path where I was supposed to be correctly, hence the errors.

All fixed now.

Offline

#5 2014-04-30 19:07:04

Saint0fCloud
Member
Registered: 2009-03-31
Posts: 137

Re: [SOLVED] Unable to create a file in a script

Xyne wrote:

I don't understand why you're catting an empty string to the file to create it nor have I ever seen ">|" before.

'>|' is a zsh/ksh-ism

>| word
Same as >, except that the file is truncated to zero length if it exists, even if CLOBBER is unset.

Offline

#6 2014-04-30 19:08:43

publicus
Member
Registered: 2014-01-01
Posts: 129

Re: [SOLVED] Unable to create a file in a script

Saint0fCloud wrote:
Xyne wrote:

I don't understand why you're catting an empty string to the file to create it nor have I ever seen ">|" before.

'>|' is a zsh/ksh-ism

>| word
Same as >, except that the file is truncated to zero length if it exists, even if CLOBBER is unset.

Yes, I have the clobber setting turned on (and it still works on machines without the clobber setting turned on.)

Offline

#7 2014-04-30 19:22:27

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: [SOLVED] Unable to create a file in a script

Thanks for the clarification of ">|".

When redirecting data to a file with ">", is the file not always truncated to the length of the redirected content in zsh/ksh? This seems to be the case in bash. If not, does it just overwrite data at the beginning of the file?


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#8 2014-04-30 20:00:25

publicus
Member
Registered: 2014-01-01
Posts: 129

Re: [SOLVED] Unable to create a file in a script

Xyne wrote:

Thanks for the clarification of ">|".

When redirecting data to a file with ">", is the file not always truncated to the length of the redirected content in zsh/ksh? This seems to be the case in bash. If not, does it just overwrite data at the beginning of the file?

Based on my exprience with bash and zsh, it just nukes the file contents, just like >.  However, the task is less likely to be done by human error when >> was expected and inadvertedly blowing your original away.

Offline

Board footer

Powered by FluxBB