Jump to content

[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?

Link to comment

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
Link to comment
  • vitor changed the title to [SOLVED] Generate custom file names with bash

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...