0

I have bash script that use username and password as argument, so I what to delete that command from history,

I've tried to add:

history -d ${history 1 | awk '{print $1}'}

But I get:

${history 1 | awk '{print $1}'}: bad substitution

Then I tried:

history -d ${history 1 | awk '{print $1}'}

But nothig is happened.

I also try to wite the last command's number to another file and then cat

history -d $(cat tst.txt)

and also nothing happened...

Is there any suggestion for doing that?

Thanks a lot!

Mor.sound
  • 25
  • 5
  • This might help in interactive `bash`: https://www.baeldung.com/linux/delete-commands-history – Cyrus May 29 '22 at 00:00
  • Thanks for your answer; but I have tried this before, forme that article I toke the ide to run the fist command. – Mor.sound May 29 '22 at 00:06
  • If you want to delete the last line of the history from your called script: I assume that this is not possible. – Cyrus May 29 '22 at 00:12
  • So bad... Thatnks a lot! – Mor.sound May 29 '22 at 00:26
  • 3
    Having the password as argument is a very bad idea, even if you eventually delete it from history it would be visible using `ps` while the process runs. – Diego Torres Milano May 29 '22 at 00:44
  • Do you have another suggestion for mounting with another LDAP user each time? – Mor.sound May 29 '22 at 03:08
  • Can you put the password in a text file and read it in the script? It would avoid password in the command. Then you secure the file with permissions. – Nic3500 May 29 '22 at 03:42
  • No, becouse it's diffrent user each time... Part of the script is mounting cifs shared folder, so the user should add his username and password. there are few users that sould run this script. – Mor.sound May 29 '22 at 04:45
  • @Mor.sound, instead of putting the password on the command line, have the program read it from the terminal (`read -s ...`). See [How to get a password from a shell script without echoing](https://stackoverflow.com/q/3980668/4154375). – pjh May 29 '22 at 21:45

1 Answers1

0

I can see two ways of achieving this.

  1. your_script; history -d $(history 1)
  2. unset HISTFILE; your_script; HISTFILE=~/.history
Yuri Ginsburg
  • 2,302
  • 2
  • 13
  • 16