Jump to content

Bash simple question

erikpc43

Hello,

I just have one simple question regarding bash programming language. I'm writing a bash script and I came across a weird problem. If u use command in terminal in some subdirectory like chmod -R 777 *  --> This would give all rwx permisions to all folders in current folder and any other subfolders, because its recursive. But if i try to use it in the script it wouldn't work, saying there is not any destination or file named *. Why is that?

 

 

 

thanks

Link to comment
Share on other sites

Link to post
Share on other sites

show the script

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, ComputerGeekFarmBoy said:

Have you tried 

chmod 777 ./*

??

 

Does not work.

Link to comment
Share on other sites

Link to post
Share on other sites

9 minutes ago, erikpc43 said:

Why is that?

There's something you're doing wrong in your script. Show the script.

Hand, n. A singular instrument worn at the end of the human arm and commonly thrust into somebody’s pocket.

Link to comment
Share on other sites

Link to post
Share on other sites

I would agree then that showing the script would be useful as well as giving us information on the OS and the shell you are currently useing.

Link to comment
Share on other sites

Link to post
Share on other sites

11 minutes ago, Sauron said:

show the script

cd $4 && chmod -R 777 *

there is no point in showing rest of the script, I tried using -x in beginning of the script and all other commands execute just fine. And also 4th argument is a directory if u wonder.

edit: linux version: Mint 19.3 and /bin/bash.

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, erikpc43 said:

cd $4 && chmod -R 777 *

$4 should be in quotes in case there are special-characters, like e.g. space, in the directory's name, for one.

Hand, n. A singular instrument worn at the end of the human arm and commonly thrust into somebody’s pocket.

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, erikpc43 said:

cd $4 && chmod -R 777 *

there is no point in showing rest of the script

That on its own works perfectly for me, what are you passing as $4?

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, WereCatf said:

$4 should be in quotes in case there are special-characters, like e.g. space, in the directory's name, for one.

O shieet, my bad. I already know u need to do this and I always forget, ffs haha. Thanks anyway.

Link to comment
Share on other sites

Link to post
Share on other sites

5 minutes ago, Sauron said:

That on its own works perfectly for me, what are you passing as $4?

directory with some subfolders.

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, erikpc43 said:

directory with some subfolders.

What exactly is the value of $4?

 

Not that it matters if @WereCatf's suggestion solved the problem... but if you had posted the script in the OP and said exactly what the path was we'd have been able to answer this immediately rather than having to go back and forth like this trying to pry information out of you.

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

At this point you would need to show us at least 2 more pieces of data.  

1.)  The actual assignment of variable $4.

2.)  A sample of the actual input you expect to give this.

 

Without these this simply works according to what we use for testing in our vain attempts to render you assistance.  More information is always better than less.

 

It would be best to post the entire bash script, but if you feel extermely secretive then that extra data may be helpful.  If you wish for anyone else to be of help that is.

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Sauron said:

What exactly is the value of $4?

 

Not that it matters if @WereCatf's suggestion solved the problem... but if you had posted the script in the OP and said exactly what the path was we'd have been able to answer this immediately rather than having to go back and forth like this trying to pry information out of you.

I'm sorry. I just don't use furums much and it seemed like its a simple fix. It's /home/erik/games. And the output is chmod: cannot accesss '* ': No such file or directory. 

Link to comment
Share on other sites

Link to post
Share on other sites

Though there is simple possible angle I did not think of earlier.  Is there any data in said directory to chmod?

 

If there are no files or directories to chmod it will give you the error.

chmod: cannot access '*': No such file or directory

 

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, ComputerGeekFarmBoy said:

Though there is simple possible angle I did not think of earlier.  Is there any data in said directory to chmod?

 

If there are no files or directories to chmod it will give you the error.

chmod: cannot access '*': No such file or directory 

 

Yes, there are couple of folders in given directory which is /home/erik/games.

Link to comment
Share on other sites

Link to post
Share on other sites

do this instead of your 

cd $4 chmod 777 * 

command.

 

echo "$4"

cd $4

ls -lha

 

and print that output to us.  

 

I created a test directory and did what you are doing with just a empty subfolder and chmod 777 * works just fine.

 

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, erikpc43 said:

I'm sorry. I just don't use furums much and it seemed like its a simple fix. It's /home/erik/games. And the output is chmod: cannot accesss '* ': No such file or directory. 

Do you have #!/bin/bash at the top of your script? Do you have quotes around the asterisk?

Hand, n. A singular instrument worn at the end of the human arm and commonly thrust into somebody’s pocket.

Link to comment
Share on other sites

Link to post
Share on other sites

It would also be helpful to just run

 

ls -lha /home/erik/games

and show that output as well.

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, WereCatf said:

Do you have #!/bin/bash at the top of your script? Do you have quotes around the asterisk?

yes, both.

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, erikpc43 said:

yes, both.

Remove the quotes from the asterisk.

Hand, n. A singular instrument worn at the end of the human arm and commonly thrust into somebody’s pocket.

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, WereCatf said:

Remove the quotes from the asterisk.

still same output

Link to comment
Share on other sites

Link to post
Share on other sites

5 minutes ago, erikpc43 said:

I'm sorry. I just don't use furums much and it seemed like its a simple fix. It's /home/erik/games. And the output is chmod: cannot accesss '* ': No such file or directory. 

It works perfectly for me so I ask you once again to show us the whole script and the way you call it.

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, erikpc43 said:

still same output

Mate, you are still doing something wrong and you're not giving enough information on how to fix it. The following does work perfectly fine in bash:
 

#!/bin/bash
cd "$4" && chmod -R 777 *

 

Hand, n. A singular instrument worn at the end of the human arm and commonly thrust into somebody’s pocket.

Link to comment
Share on other sites

Link to post
Share on other sites

Nevermind. Got the problem maker. The permissions on the first folder weren't set right.

Link to comment
Share on other sites

Link to post
Share on other sites

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

×