I have some script, that uses files in directories around it. It uses command. It should work from any directory where I run this script, but when I run a symbolic link that points to that script I get the path of symbolic link. So I get the output of dirname rather than the path of the script itself. Any
Tag: bash
How can I recall the argument of the previous bash command?
Is there a way in Bash to recall the argument of the previous command? I usually do vi file.c followed by gcc file.c. Is there a way in Bash to recall the argument of the previous command? Answer You can use $_ or !$ to recall the last argument of the previous command. Also Alt + . can be used
BASH: how to perform arithmetic on numbers in a pipe
I am getting a stream of numbers in a pipe, and would like to perform some operations before passing them on to the next section, but I’m a little lost about how I would go about it without breaking the pipe. for example Would you have any ideas on how to make something like this work? The actual operat…
linux script that monitors file changes within folders (like autospec does!)
I want to automatically kick off a build whenever a file changes. I’ve used autospec (RSpec) in Ruby and loved that. How can this be done in bash? Answer After reading replies to other posts, I found a post (now gone), I created this script :-
Convert .cshrc to .bashrc [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 6 years ago. Improve this question I am new to Linux and I am trying to compile some code that needs environment variables set …
Parsing result of Diff in Shell Script
I want to compare two files and see if they are the same or not in my shell script, my way is: Basically, if they are the same ${diff_output} should contain nothing and the above test would evaluate to true. But when I run my script, it says [: too many arguments On the if [….] line. Any ideas? Answer
Prevent * to be expanded in the bash script
Linux bash script: Execution results: * is expanded to the list of files, which is actually script itself. How can I prevent this and see actual variable value? In general case, var can be more complicated than *, for example: home/alex/mydir/*. Answer you need to escape your variables, too: And in your funct…
linux batch rename directories and strip # character from name
i have a directory with a lot of subdirectories with a # infront of them: I want to rename them all and remove the # caracter I tried to do: but didn’t seem to work. Any ideas on this. Thanks Answer Just use use -n just to check that what you think it would happen really happens. In you example
How do I use the linux flock command to prevent another root process from deleting a file?
I would like to prevent one of my root processes from deleting a certain file. So I came across the flock command, it seems to fit my need, but I didn’t get its syntax. If I only indicate a shared lock, it doesn’t work: If I add a timeout parameter, it still doesn’t work: It seems that way, …
Surprise! the shell suggests command line switches
I noticed that the bash shell can suggest command line switches for your command. Just type your command, a dash (-) and type tab. The shell will show you available switches. For example, try: and press tab – Surprise! The question is: How do I interface with this feature. I.e., if I write a program tha…