Score:-2

Error concatenating directory path in a bash script

zw flag

I have over-complicated this problem with if/then scripts and super simple one line commands but for some reason I keep getting stumped.

I am trying to create a new directory a-e and place the files a,b,c,d,e inside of it. For some reason it will create the directory just fine but places the files inside of the ps directory instead of the new directory.

#!/bin/bash
    
mkdir /home/adminuser/ps/a-e && touch /home/adminuser/ps/a-e {a..e}  
guiverc avatar
cn flag
You've tagged this as being wanted for *Ubuntu Touch*, ie. a phone or tablet device using the PHONE OS now called Lomiri (*previously called Ubuntu Touch*). If you want people to see or refer to the link you provided in your title; it needs to be in your actual question text (*any click on the title will only open this page! and some devices/setups won't show the title when you view this page anyway; thus all details need to be in your actual question text*)
user16217248 avatar
cw flag
What kind of title is that?
Raffa avatar
jp flag
`touch /home/adminuser/ps/a-e {a..e}` will do two things: 1) Update the modification/access/change time of the already existing directory `/home/adminuser/ps/a-e` and 2) create five files `a, b, c, d and e` in your current working directory ... `ps` happened to be your current working directory and that is why ... `touch` takes arguments separated by spaces and therefore your passed arguments are actually 6 and not 5 as you expected.
Esther avatar
es flag
you just want a `/` instead of a space there: `touch /home/adminuser/ps/a-e/{a..e} `
Score:3
as flag

Looks like maybe the last forward slash is missing to connect the path of the a-e directory and the filenames to be created?

Try touch /home/adminuser/ps/a-e/{a..e} and see if that works?

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.