Skip to content

Tag: shell

Make directory structure from forward slashes

Im pulling an html document from a windows machine onto my linux box and the issue is the directory structure is not maintained between the two. This is how it looks in linux Im thinking of using a bash script that will change the “” into a “/” essentially making a folder. Im guessing …

String usage with {} in bash

I have a kind of the following strings and I wan to call: in order to get “aaa.bbb.” for str1 and “aaa.” for str2 what should I use as expression inside {} Answer Use it like this:

Accessing Default directory in perl

I am having a perl script which is taking a directory path as input and then script iterates through all the files present in that directory. For each file it calls some other function. Here is the script: My question here is when i am reading input directory, in case if does not exists how can make above scr…

setuid(0) fails to execute for root owned program

I need to write some code which can gain root priveleges and execute system level operations. Here’s what I’ve written (this is not the actual code, just to test if I’m doing things correctly or not): After doing gcc -o setuid setuid.c, I run ls -al on this to get following results: Trying t…

Pidof not finding the process

I want to find out a shell script process ID using pidof or ps command or any. All i want is only the process id of it. I have used ‘pidof -x test.sh’. Which is not working. Note: I don’t want to invoke the /bin/sh or /bin/bash – because the script will not work. If i invoke /bin/sh in…

Linux C++ Detect user shell (csh,bash,etc)

I have a C++ application that needs to make shell specific commands using system calls. Is there a way to detect which shell the user is running? (Csh/Bash/etc). Thanks Elaborate I’m trying to work with some code that forks off via system a rsh call that has a sequence of commands that are using setenv …

bash command not found when setting a variable

I am writing a shell script where I am setting few variables, whose value is the output of commands. The errors I get are: now, I did read other similar questions and based on it, I tried various things: spliting command into two calls tried using backticks tried using $() But in every case the command output…

Is it possible to break out of a restricted (custom) shell?

Not sure if this is the right place to ask. Say I write a shell that takes stdin input, filters this input so let’s say only certain commands like ls (list contents of binary directory and subdirectory) update (git clone) build (go build) test (go test) start (systemctl start this.service only) stop (sy…

Arrays in Shell Script, not Bash

I am probably just having a brain fart, but I can not for the life of me figure out how to loop through an array in shell script, not bash. Im sure the answer is on stackoverflow somewhere already, but I can not find a method of doing so without using bash. For my embedded target system bash is not