Score:1

running series of commands gives other result than running them on script

fr flag

this is the script:

#!/bin/sh
rm -rf git/
mkdir -p git/{c,ds/{include,test},projects,quizzes,system_programming}
find git/ -type d -exec touch {}/dummy.md \;

This is the wanted result:

git/
├── c
│   └── dummy.md
├── ds
│   ├── dummy.md
│   ├── include
│   │   └── dummy.md
│   └── test
│       └── dummy.md
├── dummy.md
├── projects
│   └── dummy.md
├── quizzes
│   └── dummy.md
└── system_programming
    └── dummy.md

7 directories, 8 files

That happens when I run each of the commands separately one by one.

When I run the script, by changing its permissions: chmod +x script_name.sh

I get:

git/
├── {c,ds
│   ├── dummy.md
│   └── {include,test},projects,quizzes,system_programming}
│       └── dummy.md
└── dummy.md

2 directories, 3 files

I see the problem is in mkdir command by creating the wrong hierarchy of directories.

So,I checked the chmod command,
I run chmod +x+w script_name.sh but I get the same result.

Why is that?
Thanks.

cn flag
Your problem is with the she-bang, "sh". bash is what expands the { and }. You probably use bash on command line and /bin/sh is pointed to probably dash. Use `#!/bin/bash`,
fr flag
Thanks, that solved the problem. So, if I want to use a command that has `{ }` in script, so I must use `#!/bin/bash` instead of `#!/bin/sh`?
fr flag
@muru Thanks, that clarifies.
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.