Jump to content
Niklas

[SOLVED] Generate custom file names with bash

Recommended Posts

Hey,

I try to create a workflow that create a new file in my Notes app. It works. But I want that file name is automatically generated from date, time and my query. I add a bash script what takes all these things and use the output as file name:

But the problem is, that the query output is shown in a new line.

 

My code:

date +"%Y%m%d%H%M"

echo -n $date-{query}

 

My output:

202007282050
-fdjspj


What I want as output:

202007282050-fdjspj


Is there somebody who can help me to fix this code?

Share this post


Link to post
Posted (edited)

Your mistake is that your date +"%Y%m%d%H%M" command also prints its output. You aren’t actually assigning it to a variable (which is what you seem to want/think is happening).

 

The correct version of what you're trying is:

# use var=$( ... ) to assign output of a command to a variable
date="$( date +"%Y%m%d%H%M" )"
echo -n $date-{query}

There’s no need for two commands, however. You can stick it all in one echo statement. And finally, you shouldn’t use {query} (it’s only there for legacy support). Use “with input as argv” instead.


In that case, your command becomes: echo -n "$( date +%Y%m%d%H%M )-$1"

 

Edited by deanishe

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...