Shell Scripting again
Script for chmod (Use exec)
Typing “cmod +x file” every time you want to add execute permission to a shell script is a bit of a pain. Write a shell script called cx, which will run chmod for you. Make sure your cx script will change the modes of all files if used as: cx fiel1 file2 file3 file4 Can someone also help me answer the above... |
for one file it's simple.
#!/bin/sh chmod +x $1 Save the file as cx And this would be run like cx filename But the even easier way is to create an alias. I don't know if chmod can take multiple files, never tried it, but I guess it can. No way of verifying now as I am nowhere near a linux box. You could create an alias like this: alias cx='chmod +x' Now everytime you run cx actually the chmod 'x gets run. But be carefull, check that cx doesn't already exist as you might do some weird stuff. If cx would be a name of a system file used frequently, then making an alias with the same name would cause problems, because instead of the cx from the system, chmod +x would be called. And you don't want some program randomly changing file permissions to x, now do you? Anyway alias is the way to go if you ask me. Just put a line like this in your .bashrc file: alias cx='chmod +x' |
One minor note about the post above. Instead of using $1, use $@
Using $@ means that _all_ files you pass to the script are used, as compared to just the first one. And I would suggest an alias, basically: Code:
alias cx='chmod +x $@' Code:
cx one two three |
Don't want to be rude ut just a correction of the above script. I think the alias cx='chmod +x $@" wouldn't work, because cx has no arguments to go with.
this way cx would be substituted by chmod +x $@ and $@ is not yet set in cx itself. Well if you need a bash script you could do this: for i in $@ do chmod +x $i done |
how about this
#!/bin/sh chmod +x "$@" this will allow:cx 'a p p l e' apple 'a pp l e' and add exe permission to three above files |
Quote from the LQ rules:
Quote:
|
instead of making a $Script...........one can add this to a right click context menu...........this is from a book
Quote:
Quote:
|
Lets try to kill a fly with a shotgun, ha?
alias cx='chmod u+x $@' works just fine. |
marghorp, did you even try the script before you (wrongly) assumed it didn't work? :rolleyes:
As I said (and frankie_DJ), using: Code:
alias cx='chmod +x $@' |
All times are GMT -5. The time now is 07:53 AM. |