Jump to content

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
https://linustechtips.com/topic/1169097-bash-simple-question/
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
https://linustechtips.com/topic/1169097-bash-simple-question/#findComment-13408283
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
https://linustechtips.com/topic/1169097-bash-simple-question/#findComment-13408303
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
https://linustechtips.com/topic/1169097-bash-simple-question/#findComment-13408353
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
https://linustechtips.com/topic/1169097-bash-simple-question/#findComment-13408363
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
https://linustechtips.com/topic/1169097-bash-simple-question/#findComment-13408382
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
https://linustechtips.com/topic/1169097-bash-simple-question/#findComment-13408393
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
https://linustechtips.com/topic/1169097-bash-simple-question/#findComment-13408404
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
https://linustechtips.com/topic/1169097-bash-simple-question/#findComment-13408425
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
https://linustechtips.com/topic/1169097-bash-simple-question/#findComment-13408440
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

×